mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] tlv: register_device() error handling
@ 2025-12-01 14:12 Jonas Rebmann
  2025-12-01 14:20 ` Ahmad Fatoum
  2025-12-02  6:52 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Jonas Rebmann @ 2025-12-01 14:12 UTC (permalink / raw)
  To: Sascha Hauer, BAREBOX; +Cc: Jonas Rebmann

register_device() returns 0 on success, or an error, which must be
handled appropriately.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
Resolves coverity CID 584716 (Unchecked return value).
---
 common/tlv/bus.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/common/tlv/bus.c b/common/tlv/bus.c
index a59f8d297a..36a3022fdf 100644
--- a/common/tlv/bus.c
+++ b/common/tlv/bus.c
@@ -23,6 +23,7 @@ struct tlv_device *tlv_register_device(struct tlv_header *header,
 	const char *name = NULL;
 	struct device *dev;
 	static int id = 0;
+	int ret;
 
 	tlvdev = xzalloc(sizeof(*tlvdev));
 
@@ -46,7 +47,12 @@ struct tlv_device *tlv_register_device(struct tlv_header *header,
 
 	dev->device_node = of_new_node(tlv_parent_node, dev_name(dev));
 	dev->device_node->dev = dev;
-	register_device(dev);
+	ret = register_device(dev);
+	if (ret) {
+		pr_err("Failed to register device %s, %d\n", name, ret);
+		free(tlvdev);
+		return ERR_PTR(ret);
+	}
 
 	return tlvdev;
 }

---
base-commit: ec00fef65d808f8bc9c5655262b0e4f8ce2c4e92
change-id: 20251201-tlv-hardening-fd07381bc3f8

Best regards,
--  
Jonas Rebmann <jre@pengutronix.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tlv: register_device() error handling
  2025-12-01 14:12 [PATCH] tlv: register_device() error handling Jonas Rebmann
@ 2025-12-01 14:20 ` Ahmad Fatoum
  2025-12-02  6:52 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-12-01 14:20 UTC (permalink / raw)
  To: Jonas Rebmann, Sascha Hauer, BAREBOX

Hi,

On 12/1/25 3:12 PM, Jonas Rebmann wrote:
> register_device() returns 0 on success, or an error, which must be
> handled appropriately.
> 
> Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
> ---
> Resolves coverity CID 584716 (Unchecked return value).
> ---
>  common/tlv/bus.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/common/tlv/bus.c b/common/tlv/bus.c
> index a59f8d297a..36a3022fdf 100644
> --- a/common/tlv/bus.c
> +++ b/common/tlv/bus.c
> @@ -23,6 +23,7 @@ struct tlv_device *tlv_register_device(struct tlv_header *header,
>  	const char *name = NULL;
>  	struct device *dev;
>  	static int id = 0;
> +	int ret;
>  
>  	tlvdev = xzalloc(sizeof(*tlvdev));
>  
> @@ -46,7 +47,12 @@ struct tlv_device *tlv_register_device(struct tlv_header *header,
>  
>  	dev->device_node = of_new_node(tlv_parent_node, dev_name(dev));
>  	dev->device_node->dev = dev;
> -	register_device(dev);
> +	ret = register_device(dev);
> +	if (ret) {
> +		pr_err("Failed to register device %s, %d\n", name, ret);

Please drop the error message, there is a single failure mode anyway and
-EINVAL is descriptive enough.

> +		free(tlvdev);
> +		return ERR_PTR(ret);
> +	}
>  
>  	return tlvdev;
>  }
> 
> ---
> base-commit: ec00fef65d808f8bc9c5655262b0e4f8ce2c4e92
> change-id: 20251201-tlv-hardening-fd07381bc3f8
> 
> Best regards,
> --  
> Jonas Rebmann <jre@pengutronix.de>
> 
> 
> 

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tlv: register_device() error handling
  2025-12-01 14:12 [PATCH] tlv: register_device() error handling Jonas Rebmann
  2025-12-01 14:20 ` Ahmad Fatoum
@ 2025-12-02  6:52 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2025-12-02  6:52 UTC (permalink / raw)
  To: BAREBOX, Jonas Rebmann


On Mon, 01 Dec 2025 15:12:43 +0100, Jonas Rebmann wrote:
> register_device() returns 0 on success, or an error, which must be
> handled appropriately.
> 
> 

Applied, thanks!

[1/1] tlv: register_device() error handling
      https://git.pengutronix.de/cgit/barebox/commit/?id=debc16173615 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-02  6:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-01 14:12 [PATCH] tlv: register_device() error handling Jonas Rebmann
2025-12-01 14:20 ` Ahmad Fatoum
2025-12-02  6:52 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox