mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 2/2] usb: storage: add usbdisk alias for USB storage devices
Date: Tue, 30 Jun 2026 14:39:56 +0200	[thread overview]
Message-ID: <20260630-usb-disk-alias-v1-2-d23318bcb684@pengutronix.de> (raw)
In-Reply-To: <20260630-usb-disk-alias-v1-0-d23318bcb684@pengutronix.de>

Both MMC/SD and USB storage devices can be registered as "disk0" so
there is no way to access the first USB storage device. Add an "usbdisk"
alias so a user can easily detect the presence of a USB storage device
and acces it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/storage/usb.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 2ad08183f6..6251a6e5a5 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -399,6 +399,7 @@ static int usb_stor_add_blkdev(struct us_data *us, unsigned char lun)
 	struct device *dev = &us->pusb_dev->dev;
 	struct us_blk_dev *pblk_dev;
 	int result;
+	char *diskname = NULL, *alias = NULL;
 
 	/* allocate a new USB block device */
 	pblk_dev = xzalloc(sizeof(struct us_blk_dev));
@@ -414,10 +415,12 @@ static int usb_stor_add_blkdev(struct us_data *us, unsigned char lun)
 	if (result < 0)
 		goto BadDevice;
 
-	result = cdev_find_free_index("disk");
-	dev_info(dev, "registering as disk%d\n", result);
+	diskname = xasprintf("disk%d", cdev_find_free_index("disk"));
+	alias = xasprintf("usbdisk%d", cdev_find_free_index("usbdisk"));
 
-	pblk_dev->blk.cdev.name = basprintf("disk%d", result);
+	dev_info(dev, "registering as %s (%s)\n", diskname, alias);
+
+	pblk_dev->blk.cdev.name = diskname;
 	pblk_dev->blk.blockbits = SECTOR_SHIFT;
 	pblk_dev->blk.type = BLK_TYPE_USB;
 	pblk_dev->blk.removable = true;
@@ -429,6 +432,9 @@ static int usb_stor_add_blkdev(struct us_data *us, unsigned char lun)
 		goto BadDevice;
 	}
 
+	devfs_add_alias(&pblk_dev->blk.cdev, alias);
+	free(alias);
+
 	list_add_tail(&pblk_dev->list, &us->blk_dev_list);
 	dev_dbg(dev, "USB disk device successfully added\n");
 
@@ -437,6 +443,9 @@ static int usb_stor_add_blkdev(struct us_data *us, unsigned char lun)
 BadDevice:
 	dev_dbg(dev, "%s failed with %d\n", __func__, result);
 	free(pblk_dev);
+	free(diskname);
+	free(alias);
+
 	return result;
 }
 

-- 
2.47.3




  parent reply	other threads:[~2026-06-30 12:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30 12:39 [PATCH 0/2] USB: " Sascha Hauer
2026-06-30 12:39 ` [PATCH 1/2] fs: devfs: make cdev_find_free_index() return 0 instead of an error Sascha Hauer
2026-06-30 12:39 ` Sascha Hauer [this message]
2026-07-07  6:47 ` [PATCH 0/2] USB: storage: add usbdisk alias for USB storage devices 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=20260630-usb-disk-alias-v1-2-d23318bcb684@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox