Skip to contentSkip to conversation

Remove some empty bootdev_ops structures

PATCH In review Tom Rini 3 participants 17 messages May 19 – May 23

Subsystems (4)
lore
Share & tools
lore

Tom Rini

author
#0 lore raw

cover Remove some empty bootdev_ops structures

Hey all,

As part of Marek Vasut's work to add static and/or const to structs that should have it, but do not, it exposed a small problem with the bootdev uclass. This series fixes bootdev_get_bootflow to not require the ops field in the driver to be set and then removes the empty struct from the places which had been creating one.

Signature · 1 line
Tom
author
#1 lore raw

PATCH 1/5 bootdev: Fix the case where the driver ops field is null.

In the case where a bootdev does not have a custom get_bootflow function but instead relies on default_get_bootflow to provide one, bootdev_get_bootflow was not handling the case where ops was simply not set. Restructure the function to check for "ops && ops->get_bootflow" and add appropriate log_debug calls for both cases.

---
 boot/bootdev-uclass.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
boot/bootdev-uclass.c +10 -5
index 3f8dc2c3c4e6..657804949f8d 100644
@@ -566,13 +566,18 @@ int bootdev_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
 {
 	const struct bootdev_ops *ops = bootdev_get_ops(dev);
 
-	log_debug("->get_bootflow %s,%x=%p\n", dev->name, iter->part,
-		  ops->get_bootflow);
 	bootflow_init(bflow, dev, iter->method);
-	if (!ops->get_bootflow)
-		return default_get_bootflow(dev, iter, bflow);
 
-	return ops->get_bootflow(dev, iter, bflow);
+	if (ops && ops->get_bootflow) {
+		log_debug("->get_bootflow %s,%x=%p\n", dev->name, iter->part,
+			  ops->get_bootflow);
+
+		return ops->get_bootflow(dev, iter, bflow);
+	}
+
+	log_debug("->get_bootflow %s,%x is unset\n", dev->name, iter->part);
+
+	return default_get_bootflow(dev, iter, bflow);
 }
 
 int bootdev_next_label(struct bootflow_iter *iter, struct udevice **devp,
Signature · 1 line
2.43.0
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] bootdev: Fix the case where the driver ops field is null.

Quoted 7 lines · Tom Rini

In the case where a bootdev does not have a custom get_bootflow function but instead relies on default_get_bootflow to provide one, bootdev_get_bootflow was not handling the case where ops was simply not set. Restructure the function to check for "ops && ops->get_bootflow" and add appropriate log_debug calls for both cases.

Thanks !

Reviewed-by on v1 1/5
#3 lore raw

Re: [PATCH 1/5] bootdev: Fix the case where the driver ops field is null.

In reply to Tom Rini
Quoted 8 lines · Tom Rini

bootdev: Fix the case where the driver ops field is null.

In the case where a bootdev does not have a custom get_bootflow function but instead relies on default_get_bootflow to provide one, bootdev_get_bootflow was not handling the case where ops was simply not set. Restructure the function to check for "ops && ops->get_bootflow" and add appropriate log_debug calls for both cases.

Quoted 5 lines

boot/bootdev-uclass.c | 15 ++++++++++-----

 1 file changed, 10 insertions(+), 5 deletions(-)
author
#4 lore raw

PATCH 2/5 block: ide: Drop empty bootdev_ops structure

In reply to Tom Rini

We don't need to provide an empty struct here now that the caller can handle this being empty.

---
 drivers/block/ide.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/block/ide.c +0 -4
index cab5e1bc92b2..c1a46dd2a946 100644
@@ -969,9 +969,6 @@ static int ide_bootdev_hunt(struct bootdev_hunter *info, bool show)
 	return 0;
 }
 
-struct bootdev_ops ide_bootdev_ops = {
-};
-
 static const struct udevice_id ide_bootdev_ids[] = {
 	{ .compatible = "u-boot,bootdev-ide" },
 	{ }
@@ -980,7 +977,6 @@ static const struct udevice_id ide_bootdev_ids[] = {
 U_BOOT_DRIVER(ide_bootdev) = {
 	.name		= "ide_bootdev",
 	.id		= UCLASS_BOOTDEV,
-	.ops		= &ide_bootdev_ops,
 	.bind		= ide_bootdev_bind,
 	.of_match	= ide_bootdev_ids,
 };
Signature · 1 line
2.43.0
Reviewed-by on v1 2/5
#5 lore raw

Re: [PATCH 2/5] block: ide: Drop empty bootdev_ops structure

Quoted 9 lines · Tom Rini

block: ide: Drop empty bootdev_ops structure

We don't need to provide an empty struct here now that the caller can handle this being empty.

drivers/block/ide.c | 4 ----

 1 file changed, 4 deletions(-)
author
#6 lore raw

PATCH 3/5 ata: sata: Drop empty bootdev_ops structure

In reply to Tom Rini

We don't need to provide an empty struct here now that the caller can handle this being empty.

---
 drivers/ata/sata_bootdev.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/ata/sata_bootdev.c +0 -4
index a5ca6f6fd5bb..7d5ef3c94bfa 100644
@@ -37,9 +37,6 @@ static int sata_bootdev_hunt(struct bootdev_hunter *info, bool show)
 	return 0;
 }
 
-struct bootdev_ops sata_bootdev_ops = {
-};
-
 static const struct udevice_id sata_bootdev_ids[] = {
 	{ .compatible = "u-boot,bootdev-sata" },
 	{ }
@@ -48,7 +45,6 @@ static const struct udevice_id sata_bootdev_ids[] = {
 U_BOOT_DRIVER(sata_bootdev) = {
 	.name		= "sata_bootdev",
 	.id		= UCLASS_BOOTDEV,
-	.ops		= &sata_bootdev_ops,
 	.bind		= sata_bootdev_bind,
 	.of_match	= sata_bootdev_ids,
 };
Signature · 1 line
2.43.0
Reviewed-by on v1 3/5
#7 lore raw

Re: [PATCH 3/5] ata: sata: Drop empty bootdev_ops structure

Quoted 9 lines · Tom Rini

ata: sata: Drop empty bootdev_ops structure

We don't need to provide an empty struct here now that the caller can handle this being empty.

drivers/ata/sata_bootdev.c | 4 ----

 1 file changed, 4 deletions(-)
author
#8 lore raw

PATCH 4/5 scsi: Drop empty bootdev_ops structure

In reply to Tom Rini

We don't need to provide an empty struct here now that the caller can handle this being empty.

---
 drivers/scsi/scsi_bootdev.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/scsi/scsi_bootdev.c +0 -4
index 28e4612f337c..541b021b732c 100644
@@ -37,9 +37,6 @@ static int scsi_bootdev_hunt(struct bootdev_hunter *info, bool show)
 	return 0;
 }
 
-struct bootdev_ops scsi_bootdev_ops = {
-};
-
 static const struct udevice_id scsi_bootdev_ids[] = {
 	{ .compatible = "u-boot,bootdev-scsi" },
 	{ }
@@ -48,7 +45,6 @@ static const struct udevice_id scsi_bootdev_ids[] = {
 U_BOOT_DRIVER(scsi_bootdev) = {
 	.name		= "scsi_bootdev",
 	.id		= UCLASS_BOOTDEV,
-	.ops		= &scsi_bootdev_ops,
 	.bind		= scsi_bootdev_bind,
 	.of_match	= scsi_bootdev_ids,
 };
Signature · 1 line
2.43.0
Reviewed-by on v1 4/5
#9 lore raw

Re: [PATCH 4/5] scsi: Drop empty bootdev_ops structure

Quoted 9 lines · Tom Rini

scsi: Drop empty bootdev_ops structure

We don't need to provide an empty struct here now that the caller can handle this being empty.

drivers/scsi/scsi_bootdev.c | 4 ----

 1 file changed, 4 deletions(-)
author
#10 lore raw

PATCH 5/5 virtio: Drop empty bootdev_ops structure

In reply to Tom Rini

We don't need to provide an empty struct here now that the caller can handle this being empty.

---
 drivers/virtio/virtio-uclass.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/virtio/virtio-uclass.c +0 -4
index c36e9e9b3a77..a871a1439d40 100644
@@ -400,9 +400,6 @@ UCLASS_DRIVER(virtio) = {
 	.per_device_auto	= sizeof(struct virtio_dev_priv),
 };
 
-struct bootdev_ops virtio_bootdev_ops = {
-};
-
 static const struct udevice_id virtio_bootdev_ids[] = {
 	{ .compatible = "u-boot,bootdev-virtio" },
 	{ }
@@ -411,7 +408,6 @@ static const struct udevice_id virtio_bootdev_ids[] = {
 U_BOOT_DRIVER(virtio_bootdev) = {
 	.name		= "virtio_bootdev",
 	.id		= UCLASS_BOOTDEV,
-	.ops		= &virtio_bootdev_ops,
 	.bind		= virtio_bootdev_bind,
 	.of_match	= virtio_bootdev_ids,
 };
Signature · 1 line
2.43.0
Reviewed-by on v1 5/5
#11 lore raw

Re: [PATCH 5/5] virtio: Drop empty bootdev_ops structure

Quoted 9 lines · Tom Rini

virtio: Drop empty bootdev_ops structure

We don't need to provide an empty struct here now that the caller can handle this being empty.

drivers/virtio/virtio-uclass.c | 4 ----

 1 file changed, 4 deletions(-)
#12 lore raw
In reply to Tom Rini

Hi Tom,

Quoted 3 lines · Tom Rini

This series fixes bootdev_get_bootflow to not require the ops field in the driver to be set and then removes the empty struct from the places which had been creating one.

Two more empty bootdev_ops structures fit this pattern:
nvme_bootdev_ops and usb_bootdev_ops. Please can you fold those into v2 so we clean them all up together?

Quoted 3 lines

As part of Marek Vasut's work to add static and/or const to structs that should have it, but do not, it exposed a small problem with the bootdev uclass.

BTW for patch 1 it would be useful to update the comment for bootdev_get_ops() to indicate it can return NULL - normally, we don't allow this.

Regards,
Simon

author
#13 lore raw
Quoted 11 lines · Simon Glass

Hi Tom,

Quoted 3 lines · Tom Rini

This series fixes bootdev_get_bootflow to not require the ops field in the driver to be set and then removes the empty struct from the places which had been creating one.

Two more empty bootdev_ops structures fit this pattern:
nvme_bootdev_ops and usb_bootdev_ops. Please can you fold those into v2 so we clean them all up together?

I'll follow-up and remove those later, and also update the doc and remove the mmc one.

Quoted 7 lines
Quoted 3 lines

As part of Marek Vasut's work to add static and/or const to structs that should have it, but do not, it exposed a small problem with the bootdev uclass.

BTW for patch 1 it would be useful to update the comment for bootdev_get_ops() to indicate it can return NULL - normally, we don't allow this.

Don't allow which? I get the feeling you're saying I need to audit the reset of the uclasses for optional ops fields and then see who is just setting an empty struct and fix them too..

Signature · 1 line
Tom
#14 lore raw

Hi Tom,

Quoted 10 lines · Tom Rini
Quoted 8 lines · Simon Glass

Hi Tom,

Quoted 3 lines · Tom Rini

This series fixes bootdev_get_bootflow to not require the ops field in the driver to be set and then removes the empty struct from the places which had been creating one.

Quoted 6 lines
Quoted 3 lines

Two more empty bootdev_ops structures fit this pattern:
nvme_bootdev_ops and usb_bootdev_ops. Please can you fold those into v2 so we clean them all up together?

I'll follow-up and remove those later, and also update the doc and remove the mmc one.

OK

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

As part of Marek Vasut's work to add static and/or const to structs that should have it, but do not, it exposed a small problem with the bootdev uclass.

Quoted 7 lines
Quoted 3 lines

BTW for patch 1 it would be useful to update the comment for bootdev_get_ops() to indicate it can return NULL - normally, we don't allow this.

Don't allow which? I get the feeling you're saying I need to audit the reset of the uclasses for optional ops fields and then see who is just setting an empty struct and fix them too..

No, I just mean that there should normally be an ops pointer, unless the uclass itself does not support any operations. The case of using NULL for the ops pointer is really just an optimisation. I'm fine with it, but it might create confusion for people, so it would be good to document it in the uclass header file, where supported.

Regards,
Simon

author
#15 lore raw
Quoted 35 lines · Simon Glass

Hi Tom,

Quoted 10 lines · Tom Rini
Quoted 8 lines · Simon Glass

Hi Tom,

Quoted 3 lines · Tom Rini

This series fixes bootdev_get_bootflow to not require the ops field in the driver to be set and then removes the empty struct from the places which had been creating one.

Quoted 6 lines
Quoted 3 lines

Two more empty bootdev_ops structures fit this pattern:
nvme_bootdev_ops and usb_bootdev_ops. Please can you fold those into v2 so we clean them all up together?

I'll follow-up and remove those later, and also update the doc and remove the mmc one.

OK

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

As part of Marek Vasut's work to add static and/or const to structs that should have it, but do not, it exposed a small problem with the bootdev uclass.

Quoted 7 lines
Quoted 3 lines

BTW for patch 1 it would be useful to update the comment for bootdev_get_ops() to indicate it can return NULL - normally, we don't allow this.

Don't allow which? I get the feeling you're saying I need to audit the reset of the uclasses for optional ops fields and then see who is just setting an empty struct and fix them too..

Quoted 5 lines

No, I just mean that there should normally be an ops pointer, unless the uclass itself does not support any operations. The case of using NULL for the ops pointer is really just an optimisation. I'm fine with it, but it might create confusion for people, so it would be good to document it in the uclass header file, where supported.

I'll make sure the documentation is clearer in the follow-up series. I think at this point the majority of implementation do not set one, btw.

Signature · 1 line
Tom
#16 lore raw

Hi Tom,

Quoted 37 lines · Tom Rini
Quoted 35 lines · Simon Glass

Hi Tom,

Quoted 10 lines · Tom Rini
Quoted 8 lines · Simon Glass

Hi Tom,

Quoted 3 lines · Tom Rini

This series fixes bootdev_get_bootflow to not require the ops field in the driver to be set and then removes the empty struct from the places which had been creating one.

Quoted 6 lines
Quoted 3 lines

Two more empty bootdev_ops structures fit this pattern:
nvme_bootdev_ops and usb_bootdev_ops. Please can you fold those into v2 so we clean them all up together?

I'll follow-up and remove those later, and also update the doc and remove the mmc one.

OK

Quoted 12 lines
Quoted 8 lines
Quoted 4 lines

As part of Marek Vasut's work to add static and/or const to structs that should have it, but do not, it exposed a small problem with the bootdev uclass.

BTW for patch 1 it would be useful to update the comment for bootdev_get_ops() to indicate it can return NULL - normally, we don't allow this.

Don't allow which? I get the feeling you're saying I need to audit the reset of the uclasses for optional ops fields and then see who is just setting an empty struct and fix them too..

Quoted 8 lines
Quoted 5 lines

No, I just mean that there should normally be an ops pointer, unless the uclass itself does not support any operations. The case of using NULL for the ops pointer is really just an optimisation. I'm fine with it, but it might create confusion for people, so it would be good to document it in the uclass header file, where supported.

I'll make sure the documentation is clearer in the follow-up series. I think at this point the majority of implementation do not set one, btw.

Loads of uclasses don't have operations, yes.

Regards,
Simon