All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Kees Cook <kees@kernel.org>, Vlastimil Babka <vbabka@suse.cz>,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	torvalds@linux-foundation.org, peterz@infradead.org,
	Jann Horn <jannh@google.com>,
	intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org,
	Harry Yoo <harry.yoo@oracle.com>,
	Christoph Lameter <cl@gentwo.org>
Subject: Re: [Intel-wired-lan] [RFC] slab: introduce auto_kfree macro
Date: Thu, 3 Apr 2025 20:46:20 +0300	[thread overview]
Message-ID: <Z-7JbPeMlnpspKM_@smile.fi.intel.com> (raw)
In-Reply-To: <Z-7G6_jm4SKtSO7a@casper.infradead.org>

On Thu, Apr 03, 2025 at 06:35:39PM +0100, Matthew Wilcox wrote:
> On Thu, Apr 03, 2025 at 09:59:41AM -0700, Kees Cook wrote:
> > On Wed, Apr 02, 2025 at 12:44:50PM +0200, Vlastimil Babka wrote:
> > > Cc Kees and others from his related efforts:
> > > 
> > > https://lore.kernel.org/all/20250321202620.work.175-kees@kernel.org/
> > 
> > I think, unfortunately, the consensus is that "invisible side-effects"
> > are not going to be tolerated. After I finish with kmalloc_obj(), I'd
> > like to take another run at this for basically providing something like:
> > 
> > static inline __must_check
> > void *kfree(void *p) { __kfree(p); return NULL; }
> > 
> > And then switch all:
> > 
> > 	kfree(s->ptr);
> > 
> > to
> > 
> > 	s->ptr = kfree(s->ptr);
> > 
> > Where s->ptr isn't used again.
> 
> Umm ... kfree is now going to be __must_check?  That's a lot of churn.
> 
> I'd just go with making kfree() return NULL and leave off the
> __must_check.  It doesn't need the __kfree() indirection either.
> That lets individual functions opt into the new safety.

Maybe something like

void kfree_and_null(void **ptr)
{
	__kfree(*ptr);
	*ptr = NULL;
}

?

-- 
With Best Regards,
Andy Shevchenko



WARNING: multiple messages have this Message-ID (diff)
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Kees Cook <kees@kernel.org>, Vlastimil Babka <vbabka@suse.cz>,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	torvalds@linux-foundation.org, peterz@infradead.org,
	Jann Horn <jannh@google.com>,
	intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org,
	Harry Yoo <harry.yoo@oracle.com>,
	Christoph Lameter <cl@gentwo.org>
Subject: Re: [RFC] slab: introduce auto_kfree macro
Date: Thu, 3 Apr 2025 20:46:20 +0300	[thread overview]
Message-ID: <Z-7JbPeMlnpspKM_@smile.fi.intel.com> (raw)
In-Reply-To: <Z-7G6_jm4SKtSO7a@casper.infradead.org>

On Thu, Apr 03, 2025 at 06:35:39PM +0100, Matthew Wilcox wrote:
> On Thu, Apr 03, 2025 at 09:59:41AM -0700, Kees Cook wrote:
> > On Wed, Apr 02, 2025 at 12:44:50PM +0200, Vlastimil Babka wrote:
> > > Cc Kees and others from his related efforts:
> > > 
> > > https://lore.kernel.org/all/20250321202620.work.175-kees@kernel.org/
> > 
> > I think, unfortunately, the consensus is that "invisible side-effects"
> > are not going to be tolerated. After I finish with kmalloc_obj(), I'd
> > like to take another run at this for basically providing something like:
> > 
> > static inline __must_check
> > void *kfree(void *p) { __kfree(p); return NULL; }
> > 
> > And then switch all:
> > 
> > 	kfree(s->ptr);
> > 
> > to
> > 
> > 	s->ptr = kfree(s->ptr);
> > 
> > Where s->ptr isn't used again.
> 
> Umm ... kfree is now going to be __must_check?  That's a lot of churn.
> 
> I'd just go with making kfree() return NULL and leave off the
> __must_check.  It doesn't need the __kfree() indirection either.
> That lets individual functions opt into the new safety.

Maybe something like

void kfree_and_null(void **ptr)
{
	__kfree(*ptr);
	*ptr = NULL;
}

?

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2025-04-03 17:46 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-01 13:44 [Intel-wired-lan] [RFC] slab: introduce auto_kfree macro Przemek Kitszel
2025-04-01 13:44 ` Przemek Kitszel
2025-04-02 10:32 ` [Intel-wired-lan] " Andy Shevchenko
2025-04-02 10:32   ` Andy Shevchenko
2025-04-02 10:40   ` [Intel-wired-lan] " Andy Shevchenko
2025-04-02 10:40     ` Andy Shevchenko
2025-04-02 12:19   ` [Intel-wired-lan] " Peter Zijlstra
2025-04-02 12:19     ` Peter Zijlstra
2025-04-02 12:22     ` [Intel-wired-lan] " Peter Zijlstra
2025-04-02 12:22       ` Peter Zijlstra
2025-04-02 12:57       ` [Intel-wired-lan] " Andy Shevchenko
2025-04-02 12:57         ` Andy Shevchenko
2025-04-04  3:05     ` [Intel-wired-lan] " Herbert Xu
2025-04-04  3:05       ` Herbert Xu
2025-04-02 12:21   ` [Intel-wired-lan] " Peter Zijlstra
2025-04-02 12:21     ` Peter Zijlstra
2025-04-02 12:55     ` [Intel-wired-lan] " Andy Shevchenko
2025-04-02 12:55       ` Andy Shevchenko
2025-04-02 10:44 ` [Intel-wired-lan] " Vlastimil Babka
2025-04-02 10:44   ` Vlastimil Babka
2025-04-03 16:59   ` [Intel-wired-lan] " Kees Cook
2025-04-03 16:59     ` Kees Cook
2025-04-03 17:35     ` [Intel-wired-lan] " Matthew Wilcox
2025-04-03 17:35       ` Matthew Wilcox
2025-04-03 17:46       ` Andy Shevchenko [this message]
2025-04-03 17:46         ` Andy Shevchenko
2025-04-03 18:15 ` [Intel-wired-lan] " Linus Torvalds
2025-04-03 18:15   ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z-7JbPeMlnpspKM_@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=cl@gentwo.org \
    --cc=harry.yoo@oracle.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jannh@google.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=torvalds@linux-foundation.org \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.