From: Stephen Warren <swarren@wwwdotorg.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 40/44] dm: blk: Allow blk_create_device() to allocate the device number
Date: Tue, 12 Apr 2016 14:56:39 -0600 [thread overview]
Message-ID: <570D6107.70509@wwwdotorg.org> (raw)
In-Reply-To: <1460256336-30436-41-git-send-email-sjg@chromium.org>
On 04/09/2016 08:45 PM, Simon Glass wrote:
> Allow a devnum parameter of -1 to indicate that the device number should be
> alocated automatically. The next highest available device number for that
> interface type is used.
> diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
> +int blk_find_max_devnum(enum if_type if_type)
> +{
> + struct udevice *dev;
> + int max_devnum = -ENODEV;
> + struct uclass *uc;
> + int ret;
> +
> + ret = uclass_get(UCLASS_BLK, &uc);
> + if (ret)
> + return ret;
I'm tempted to suggest that the -ENODEV special case be place here, and
return 0 instead. Of course, that would require the devnum to be a
pointer/output parameter rather than encoded into the return value, so
that other errors could still be returned. Perhaps not worth it.
My reasoning is that clients of this function should just be able to ask
"what's the next device number" and not care about implementing the
special cases, but rather rely on this function encoding everything.
This doesn't matter so much if there's only one call-site though. If
there is only one call-site, should this be static?
Hmm. This could all be solved by having the function return the next
free devnum (0..n) (or -ve error) rather than the highest used devnum.
That way, the -ENODEV special case would return 0, and clients could
just do:
devnum = blk_find_next_free_devnum(...);
if (devnum < 0)
return devnum;
and nothing else.
> @@ -428,6 +448,15 @@ int blk_create_device(struct udevice *parent, const char *drv_name,
> desc->lba = size / blksz;
> desc->part_type = PART_TYPE_UNKNOWN;
> desc->bdev = dev;
> + if (devnum == -1) {
> + ret = blk_find_max_devnum(if_type);
> + if (ret == -ENODEV)
> + devnum = 0;
I'm thinking that clients should have to care about implementing that
ever time they use the function.
> + else if (ret < 0)
> + return ret;
> + else
> + devnum = ret + 1;
> + }
> desc->devnum = devnum;
next prev parent reply other threads:[~2016-04-12 20:56 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-10 2:44 [U-Boot] [PATCH 00/44] dm: blk: Add more driver-model support for block devices Simon Glass
2016-04-10 2:44 ` [U-Boot] [PATCH 01/44] Revert "dm: sandbox: Drop the pre-DM host implementation" Simon Glass
2016-04-10 2:44 ` [U-Boot] [PATCH 02/44] dm: sandbox: Add a board for sandbox without CONFIG_BLK Simon Glass
2016-04-10 2:44 ` [U-Boot] [PATCH 03/44] pci: Drop CONFIG_SYS_SCSI_SCAN_BUS_REVERSE Simon Glass
2016-04-11 5:02 ` Bin Meng
2016-04-10 2:44 ` [U-Boot] [PATCH 04/44] dm: Rename disk uclass to ahci Simon Glass
2016-04-10 2:44 ` [U-Boot] [PATCH 05/44] Allow iotrace byte access to use an address of any size Simon Glass
2016-04-12 20:00 ` Stephen Warren
2016-04-10 2:44 ` [U-Boot] [PATCH 06/44] sandbox: Add string and 16-bit I/O functions Simon Glass
2016-04-12 20:02 ` Stephen Warren
2016-04-10 2:44 ` [U-Boot] [PATCH 07/44] sandbox: Add dummy SCSI functions Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 08/44] sandbox: Add dummy SATA functions Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 09/44] dm: scsi: Remove the forward declarations Simon Glass
2016-04-12 20:04 ` Stephen Warren
2016-04-10 2:45 ` [U-Boot] [PATCH 10/44] dm: scsi: Fix up code style Simon Glass
2016-04-12 20:05 ` Stephen Warren
2016-04-10 2:45 ` [U-Boot] [PATCH 11/44] dm: ide: Correct various code style problems Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 12/44] dm: ide: Remove the forward declarations Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 13/44] dm: sata: Fix code style problems in cmd/sata.c Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 14/44] dm: scsi: Rename CONFIG_CMD_SCSI to CONFIG_SCSI Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 15/44] dm: blk: Add a legacy block interface Simon Glass
2016-04-12 20:28 ` Stephen Warren
2016-05-01 18:56 ` Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 16/44] dm: systemace: " Simon Glass
2016-04-12 20:31 ` Stephen Warren
2016-05-01 18:56 ` Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 17/44] dm: sandbox: Add a legacy host " Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 18/44] dm: usb: Add a legacy block interface for USB storage Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 19/44] dm: mmc: Add a legacy block interface for MMC Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 20/44] dm: mmc: Add an implementation of the 'devnum' functions Simon Glass
2016-04-12 20:40 ` Stephen Warren
2016-05-01 18:56 ` Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 21/44] dm: scsi: Separate the non-command code into its own file Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 22/44] dm: ide: " Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 23/44] dm: sata: " Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 24/44] dm: disk: Use legacy block driver info for block device access Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 25/44] dm: usb: Drop the get_dev() function Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 26/44] dm: ide: " Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 27/44] dm: mmc: " Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 28/44] dm: scsi: " Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 29/44] dm: sata: " Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 30/44] dm: systemace: " Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 31/44] dm: blk: Drop the systemace.h header Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 32/44] dm: sandbox: Drop the host_get_dev() function Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 33/44] dm: part: Drop the get_dev() method Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 34/44] dm: ide: Add support for driver-model block devices Simon Glass
2016-04-12 20:49 ` Stephen Warren
2016-05-01 18:56 ` Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 35/44] dm: sandbox: Enable IDE Simon Glass
2016-04-12 20:50 ` Stephen Warren
2016-05-01 18:56 ` Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 36/44] dm: scsi: Add support for driver-model block devices Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 37/44] dm: sandbox: Enable SCSI Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 38/44] dm: sata: Add support for driver-model block devices Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 39/44] dm: sandbox: Enable SATA Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 40/44] dm: blk: Allow blk_create_device() to allocate the device number Simon Glass
2016-04-12 20:56 ` Stephen Warren [this message]
2016-05-01 18:56 ` Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 41/44] dm: blk: Add a easier way to create a named block device Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 42/44] dm: systemace: Reorder function to avoid forward declarataions Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 43/44] dm: systemace: Add driver-mode block-device support Simon Glass
2016-04-10 2:45 ` [U-Boot] [PATCH 44/44] dm: sandbox: Enable systemace Simon Glass
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=570D6107.70509@wwwdotorg.org \
--to=swarren@wwwdotorg.org \
--cc=u-boot@lists.denx.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