From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09300C36017 for ; Wed, 2 Apr 2025 12:19:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5EB2280005; Wed, 2 Apr 2025 08:19:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E0DE5280001; Wed, 2 Apr 2025 08:19:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD59C280005; Wed, 2 Apr 2025 08:19:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id ABEFF280001 for ; Wed, 2 Apr 2025 08:19:41 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 001EA16187E for ; Wed, 2 Apr 2025 12:19:42 +0000 (UTC) X-FDA: 83289009804.06.465868E Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf23.hostedemail.com (Postfix) with ESMTP id 139D8140003 for ; Wed, 2 Apr 2025 12:19:39 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b="DeX/TrKk"; dmarc=none; spf=none (imf23.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743596380; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tYWalLVq1oY7YpgCK/9TLrLFA6SrCHespTPHmhCT5W0=; b=blZazD9J9KIZsSZqgR/mkrOh8S0W1ONKD+IWhQ0S94uGa6om6D+Ja3KWs26cFCx4zmhltZ CSgrBHq8NgODaFc9N6NXQtWapjKb/DPG0q18KVuJc3RypdAIKRD/uYfAawj9BYaQL0u55x VzoK6/1o/jFn4fxz4TSTzOdTAySxM1g= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b="DeX/TrKk"; dmarc=none; spf=none (imf23.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743596380; a=rsa-sha256; cv=none; b=DvQamn7/nutmXAxvZQiq8E6qcVBknYozps9KBc8dlvUH6ZREZ1ktGVD7VvgWpu0MKqH3OR nsYAAuy1zgW1s/GgDDpqwVPD2ht3AR/+SY2R2VmnCtYooBdum280kohC5DQLvjSW2NtX9Q yUoyIaZM14wB2ZvR8sGQz87zpcKXkyk= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=tYWalLVq1oY7YpgCK/9TLrLFA6SrCHespTPHmhCT5W0=; b=DeX/TrKkUl7ChmLIkudAGakoJN wsSUgMerqtPGyl9OXs8f24kpWwBVJCMpW/mnnpHVcIc4OFtPRxqhUGuMvHw4wCWTy7pEstmV8dRqn SadtUutQ0Bhw+tvxfLx5Iy7VQHuSg3eZ7EzlI/tibq4jui7PPUzPDGdga1tKZm4PN1gijbLSSu5Yt AdWyU6i6jvl5Vs8HVhz4pa7OScaG9WOdE/0xPQ3XyXx1/O7YS7ikRMNrc3+BZ9bxl1zp5Mn9mnwly /7hMuerNACzK46FGeyFdO5XBglm5/1g1jneirQD7kOlp0jIWa3mTQpDGl+5poSLkMLitbYYaAlA9P 3LY4gU1A==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzx4C-00000007171-1r8R; Wed, 02 Apr 2025 12:19:36 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 7678D30049D; Wed, 2 Apr 2025 14:19:35 +0200 (CEST) Date: Wed, 2 Apr 2025 14:19:35 +0200 From: Peter Zijlstra To: Andy Shevchenko Cc: Przemek Kitszel , linux-kernel@vger.kernel.org, linux-mm@kvack.org, vbabka@suse.cz, torvalds@linux-foundation.org, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-toolchains@vger.kernel.org Subject: Re: [RFC] slab: introduce auto_kfree macro Message-ID: <20250402121935.GJ25239@noisy.programming.kicks-ass.net> References: <20250401134408.37312-1-przemyslaw.kitszel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam01 X-Stat-Signature: ogamyhyikybdxq37rmb51tut8x3ahyau X-Rspam-User: X-Rspamd-Queue-Id: 139D8140003 X-HE-Tag: 1743596379-678611 X-HE-Meta: U2FsdGVkX1/gBFjmB+yjX1AhtE1C3tdkvm94nwslUPsh+ilDsHjBr8wt5ieDpMqf1s90LqnSfo0/9acMZpPfi2Aa0p+Qp/vMhBTfl40P8P5vUJLf9sGG6rXnkpVdjb3x3pYzHZ9kR/WWmJTD4wtKa4b0sCyO9mgMmkJg5yw5xfY+TsubFL5/rpgm7y+uRyltL6+9rhpgaAQ9Q8eQZ4oMPV7pCtOywulgWUfy7JQpApxtJ8iGiceKWrholsYNdqFEDJsXZgGwxUSypCwpI9JTsKUCo83RRbxzPB1D06HKoob3Z3ZOeS7cL602+5XoX5NbAyOSqOj+dkYDa+HKF4se7pQdpu07utCT8wcJI8d2hhEitDcDUzSBHnCvJE1TStBGfCPbt4uU5pXZJCIK6wgOpDZx5qFck2KAEACzr7Y0wOavGixIr/eXx6v8LqkUTK8xx2stNtEEClaVN+YkXHWN0OwErYbbGAXJ/BItvaMOS84cU1lE8ln2W211XA25vK23Lc74o76nLcWjQ0CiCdmDb7T43jWT6irHVew2xlDIKzVgcmFBBYCcOAIoctJmcMVmcBZ03Z4KfhWr+RZ4euQSH9D+5wCkF22yv6y7Tg5b5BkSYFxfRAAnsLiyAis4NRwcU6ik5ridlMzEKA8UmnK7B7y+7mSiqPvCEu/FHe4aJi1uKs2c/OCjAwOFWgO1Fl7Xus3iF9gPT/+QHiDt8rgV6Fd16J9Lr/niBzcp8nHG4Kxtrg2AIqxBVuBXXTJY510bKM3RJoEu5AbprAo/AqpB00c9WjRlmw+X5wlCs2l15OHd2i4FfKbi+MuwDgxN80F3L/NcbdpHaUxgX+TsFJox9/GIyge7+drNFVtY0APAsm6YQXUXAlF54VRSuW+Ru4Xus/UFw1aNjgaQ9Z20t+AhzyU3vd2Uzu7MmMVJp9Y3IrGFjP5DMfMIes7uN38DQOmNAerFMEKKZb2S9ch2GjB 4TrPTvUC f+cDR4foPSA7rwbub/0MoJsJQWHwynIBUoqyEeCdzvOolC+rOL0a9un7NHO8VucYlLqDU9C6rr3G9c26APbdfrbF7vSz6UqgMfsAiEEmKcdPunKC2KIZx53KBwxpEHjzzb/0R6MI+3+mFtYSuNryUVqOWIEkoo8+9+ASWiaDPwGy4OQpwGi+nfvsf0ve2zns7m2TZXuWKk59YqjI1YCXqWPJdKxbR+MjIRUc//8JDN+b05xA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Apr 02, 2025 at 01:32:51PM +0300, Andy Shevchenko wrote: > On Tue, Apr 01, 2025 at 03:44:08PM +0200, Przemek Kitszel wrote: > > Add auto_kfree macro that acts as a higher level wrapper for manual > > __free(kfree) invocation, and sets the pointer to NULL - to have both > > well defined behavior also for the case code would lack other assignement. > > > > Consider the following code: > > int my_foo(int arg) > > { > > struct my_dev_foo *foo __free(kfree); /* no assignement */ > > > > foo = kzalloc(sizeof(*foo), GFP_KERNEL); > > /* ... */ > > } > > > > So far it is fine and even optimal in terms of not assigning when > > not needed. But it is typical to don't touch (and sadly to don't > > think about) code that is not related to the change, so let's consider > > an extension to the above, namely an "early return" style to check > > arg prior to allocation: > > int my_foo(int arg) > > { > > struct my_dev_foo *foo __free(kfree); /* no assignement */ > > + > > + if (!arg) > > + return -EINVAL; > > foo = kzalloc(sizeof(*foo), GFP_KERNEL); > > /* ... */ > > } > > Now we have uninitialized foo passed to kfree, what likely will crash. > > One could argue that `= NULL` should be added to this patch, but it is > > easy to forgot, especially when the foo declaration is outside of the > > default git context. The compiler *should* complain. But neither GCC nor clang actually appear to warn in this case. I don't think we should be making dodgy macros like you propose to work around this compiler deficiency. Instead I would argue we ought to get both compilers fixed asap, and then none of this will be needed.