[PATCH 1/2] cdev: pass master cdev to cdev ops

Sascha Hauer s.hauer at pengutronix.de
Mon Jun 2 03:12:25 PDT 2025


On Mon, Jun 02, 2025 at 11:03:56AM +0200, Ahmad Fatoum wrote:
> Hello Sascha,
> 
> On 6/2/25 10:51, Sascha Hauer wrote:
> > cdev partitions are cdevs themselves, but they are handled internally in
> > the devfs-core. cdev partitions should not be passed as context pointers
> > to the cdev ops though, because the drivers might do a container_of() on
> > them to retrieve their driver data. Pass the original cdev the driver
> > has registered as context to the ops. With this we can drop some quirks
> > in the nvmem core in the next step.
> 
> Given that read/write and so on take absolute offsets, I agree that this
> is a sensible change.
> 
> > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> 
> With below nit addressed:
> 
> Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> 
> > ---
> >  fs/devfs-core.c | 53 +++++++++++++++++++++++++++++++++++++++++------------
> >  1 file changed, 41 insertions(+), 12 deletions(-)
> > 
> > diff --git a/fs/devfs-core.c b/fs/devfs-core.c
> > index 5fafcaecc70d63287e0b716cc0133198c28e79e9..73a13be7336df1eb4e24e8a936986b6069f3783c 100644
> > --- a/fs/devfs-core.c
> > +++ b/fs/devfs-core.c
> > @@ -224,12 +224,21 @@ int cdev_find_free_index(const char *basename)
> >  	return -EBUSY;	/* all indexes are used */
> >  }
> >  
> > +static struct cdev *cdev_get_master(struct cdev *cdev)
> > +{
> > +	while (cdev && cdev_is_partition(cdev))
> > +		cdev = cdev->master;
> 
> This can be made into a simple if condition as we do not support links
> to links, see cdev_readlink.

This patch is not about links, it's about partitions and we can indeed
partitiion a partition.

You can try with

addpart /dev/imx-ocotp 128 at 0x10(foo)
addpart /dev/imx-ocotp.foo 64 at 0x10(foo1)

reading from the latter fails with a core dump without this patch.

As far as I can tell links are not affected by this problem as we always
resolve links by doing a cdev = cdev_readlink(cdev), so the link cdevs
are never passed down to drivers.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list