From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: kr494167@gmail.com, Rajat Gupta <rajgupt@qti.qualcomm.com>
Cc: andy.shevchenko@gmail.com, andy@kernel.org, geert@linux-m68k.org,
chris.packham@alliedtelesis.co.nz, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/3 1/3] auxdisplay: line-display: add devm_linedisp_register()
Date: Wed, 19 Aug 2026 11:01:56 +0300 [thread overview]
Message-ID: <aoVi9DJD0pE3kXBS@ashevche-desk.local> (raw)
In-Reply-To: <20260819024556.63534-2-kr494167@gmail.com>
On Wed, Aug 19, 2026 at 08:15:54AM +0530, kr494167@gmail.com wrote:
> Add devm_linedisp_register() to manage character line display registration
> via devres. This simplifies driver cleanup and prevents use-after-free
> bugs when unregistering line displays on driver detach.
This is not enough per se. Copied'n'pasted the reply I made to Rajat who
reported the issue:
-->8----8<--
> > 6. PROPOSED FIX
> >
> > Replace devm_kzalloc with plain kzalloc and tie the container
> > lifetime to the embedded device's refcount:
> >
> > --- a/drivers/auxdisplay/line-display.c
> > +++ b/drivers/auxdisplay/line-display.c
> > @@ (linedisp_release callback)
> >
> > static void linedisp_release(struct device *dev)
> > {
> > struct linedisp *linedisp = to_linedisp(dev);
> > + struct container *priv = container_of(linedisp, ...);
> >
> > kfree(linedisp->map);
> > kfree(linedisp->message);
> > kfree(linedisp->buf);
> > + kfree(priv); /* free container when refcount reaches 0 */
> > }
> >
> > Each affected driver (img-ascii-lcd, max6959, seg-led-gpio) must
> > change devm_kzalloc to kzalloc for the container struct, and ensure
> > the release function frees it. This aligns the container lifetime
> > with the embedded device refcount.
>
> That won't scale as the device drivers are free to call devm_kzalloc()
> and similar for their private data structures. What we should do is to
> prevent a device from unbinding when one or more files are open (via
> sysfs). TL;DR: downgrading devm_kzalloc() is not an option.
So, the fix as I see it is much more intrusive. The
linedisp_register() should be split to _alloc() and _register() APIs,
and then at least the first one being also wrapped with devm_*() for
users that want this. See how devm_iio_device_alloc() and
devm_iio_device_registers() are implemented.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-08-19 8:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 2:45 [PATCH 0/3] auxdisplay: add devm_linedisp_register() and fix work initialization races kr494167
2026-08-19 2:45 ` [PATCH 0/3 1/3] auxdisplay: line-display: add devm_linedisp_register() kr494167
2026-08-19 8:01 ` Andy Shevchenko [this message]
2026-08-19 2:45 ` [PATCH 0/3 2/3] auxdisplay: seg-led-gpio: fix work initialization race and convert to devm_linedisp_register() kr494167
2026-08-19 2:45 ` [PATCH 0/3 3/3] auxdisplay: max6959: " kr494167
2026-08-19 7:50 ` Andy Shevchenko
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=aoVi9DJD0pE3kXBS@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy.shevchenko@gmail.com \
--cc=andy@kernel.org \
--cc=chris.packham@alliedtelesis.co.nz \
--cc=geert@linux-m68k.org \
--cc=kr494167@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rajgupt@qti.qualcomm.com \
/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.