mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	BAREBOX <barebox@lists.infradead.org>
Subject: Re: [PATCH v2 02/13] storage-by-alias: drop fake cdev
Date: Mon, 15 Dec 2025 12:15:21 +0100	[thread overview]
Message-ID: <59162d54-9dfe-4a45-947d-145177aaa125@pengutronix.de> (raw)
In-Reply-To: <20251209-devfs-v2-2-62ae16698cff@pengutronix.de>



On 12/9/25 1:51 PM, Sascha Hauer wrote:
> storage-by-alias creates its own cdev, but that is never used. The only
> purpose is to create a cdev with its own device node which otherwise
> links to the original cdev. This means we can drop all the cdev
> operations and use the newly created devfs_create_link_node() with the
> same effect.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
>  drivers/misc/storage-by-alias.c | 120 +++-------------------------------------
>  1 file changed, 7 insertions(+), 113 deletions(-)
> 
> diff --git a/drivers/misc/storage-by-alias.c b/drivers/misc/storage-by-alias.c
> index 2c498e0d0483ca71093612382c78372df399c437..6c759867ccbb7a7b4bc922152699eb346d42d271 100644
> --- a/drivers/misc/storage-by-alias.c
> +++ b/drivers/misc/storage-by-alias.c
> @@ -24,102 +24,8 @@ static LIST_HEAD(sba_list);
>  struct sba {
>  	char *alias;
>  	struct device *dev;
> -	struct cdev *rcdev;
> -	struct cdev cdev;
>  	struct list_head list;
> -};
> -
> -static ssize_t sba_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags)
> -{
> -	struct sba *sba = cdev->priv;
> -
> -	return cdev_read(sba->rcdev, buf, count, offset, flags);
> -}
> -
> -static ssize_t sba_write(struct cdev *cdev, const void *buf, size_t count, loff_t offset, ulong flags)
> -{
> -	struct sba *sba = cdev->priv;
> -
> -	return cdev_write(sba->rcdev, buf, count, offset, flags);
> -}
> -
> -static int sba_ioctl(struct cdev *cdev, unsigned int request, void *buf)
> -{
> -	struct sba *sba = cdev->priv;
> -
> -	return cdev_ioctl(sba->rcdev, request, buf);
> -}
> -
> -static int sba_open(struct cdev *cdev, unsigned long flags)
> -{
> -	struct sba *sba = cdev->priv;
> -
> -	return cdev_open(sba->rcdev, flags);
> -}
> -
> -static int sba_close(struct cdev *cdev)
> -{
> -	struct sba *sba = cdev->priv;
> -
> -	cdev_close(sba->rcdev);
> -
> -	return 0;
> -}
> -
> -static int sba_flush(struct cdev *cdev)
> -{
> -	struct sba *sba = cdev->priv;
> -
> -	return cdev_flush(sba->rcdev);
> -}
> -
> -static int sba_erase(struct cdev *cdev, loff_t count, loff_t offset)
> -{
> -	struct sba *sba = cdev->priv;
> -
> -	return cdev_erase(sba->rcdev, count, offset);
> -}
> -
> -static int sba_protect(struct cdev *cdev, size_t count, loff_t offset, int prot)
> -{
> -	struct sba *sba = cdev->priv;
> -
> -	return cdev_protect(sba->rcdev, count, offset, prot);
> -}
> -
> -static int sba_discard_range(struct cdev *cdev, loff_t count, loff_t offset)
> -{
> -	struct sba *sba = cdev->priv;
> -
> -	return cdev_discard_range(sba->rcdev, count, offset);
> -}
> -
> -static int sba_memmap(struct cdev *cdev, void **map, int flags)
> -{
> -	struct sba *sba = cdev->priv;
> -
> -	return cdev_memmap(sba->rcdev, map, flags);
> -}
> -
> -static int sba_truncate(struct cdev *cdev, size_t size)
> -{
> -	struct sba *sba = cdev->priv;
> -
> -	return cdev_truncate(sba->rcdev, size);
> -}
> -
> -static struct cdev_operations sba_ops = {
> -	.read = sba_read,
> -	.write = sba_write,
> -	.ioctl = sba_ioctl,
> -	.open = sba_open,
> -	.close = sba_close,
> -	.flush = sba_flush,
> -	.erase = sba_erase,
> -	.protect = sba_protect,
> -	.discard_range = sba_discard_range,
> -	.memmap = sba_memmap,
> -	.truncate = sba_truncate,
> +	bool populated;
>  };
>  
>  static int sba_add_partitions(struct cdev *rcdev, void *data)
> @@ -127,29 +33,17 @@ static int sba_add_partitions(struct cdev *rcdev, void *data)
>  	struct sba *sba = data;
>  	int ret;
>  
> -	dev_dbg(sba->dev, "Adding %s -> %s\n", sba->alias, rcdev->name);
> -
> -	if (sba->rcdev)
> +	if (sba->populated)
>  		return 0;
>  
> -	sba->rcdev = rcdev;
> -	sba->cdev.link = rcdev;
> -	sba->cdev.name = sba->alias;
> -	sba->cdev.size = rcdev->size;
> -	sba->cdev.ops = &sba_ops;
> -	sba->cdev.dev = sba->dev;
> -	sba->cdev.priv = sba;
> +	dev_info(sba->dev, "Adding %s -> %s\n", sba->alias, rcdev->name);
>  
> -	if (rcdev->flags & DEVFS_WRITE_AUTOERASE)
> -		sba->cdev.flags |= DEVFS_WRITE_AUTOERASE;
> +	ret = devfs_create_link_node(rcdev, sba->alias, sba->dev->device_node);
> +	if (ret)
> +		return ret;
>  
> -	ret = devfs_create(&sba->cdev);
> -	if (ret) {
> -		dev_err(sba->dev, "Failed to create cdev: %pe\n", ERR_PTR(ret));
> -		return 0;
> -	}
> +	sba->populated = true;
>  
> -	of_parse_partitions(&sba->cdev, sba->dev->of_node);
>  	return 0;
>  }
>  
> 

-- 
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 |




  reply	other threads:[~2025-12-15 11:15 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-09 12:51 [PATCH v2 00/13] fs: Use device special nodes for devfs Sascha Hauer
2025-12-09 12:51 ` [PATCH v2 01/13] fs: devfs-core: add devfs_create_link_node() Sascha Hauer
2025-12-15 11:14   ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 02/13] storage-by-alias: drop fake cdev Sascha Hauer
2025-12-15 11:15   ` Ahmad Fatoum [this message]
2025-12-09 12:51 ` [PATCH v2 03/13] fs: implement mknod Sascha Hauer
2025-12-15 11:19   ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 04/13] commands: add mknod command Sascha Hauer
2025-12-15 11:21   ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 05/13] fs: ramfs: add device file support Sascha Hauer
2025-12-15 11:22   ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 06/13] cdev: add cdev_size() helper Sascha Hauer
2025-12-15 11:22   ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 07/13] fs: fix st_size for device files Sascha Hauer
2025-12-15 11:24   ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 08/13] fs: retire devfs as filesystem Sascha Hauer
2025-12-15 11:25   ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 09/13] fs: include cdevname in struct stat Sascha Hauer
2025-12-15 11:25   ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 10/13] fs: stat_print: get cdevname from stat Sascha Hauer
2025-12-15 11:26   ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 11/13] common: cdev-alias: rename struct Sascha Hauer
2025-12-15 11:27   ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 12/13] fs: replace cdev links with aliases Sascha Hauer
2025-12-15 11:31   ` Ahmad Fatoum
2025-12-15 12:17     ` Sascha Hauer
2025-12-09 12:51 ` [PATCH v2 13/13] ls: use ~0 for FILE_SIZE_STREAM Sascha Hauer
2025-12-15 11:32   ` Ahmad Fatoum
2025-12-15 12:16 ` [PATCH v2 00/13] fs: Use device special nodes for devfs Sascha Hauer

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=59162d54-9dfe-4a45-947d-145177aaa125@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox