Skip to contentSkip to conversation

i3c: master: Fix potentially uninit variable

PATCH-next Advait Dhamorikar 2 participants 4 messages Nov 19, 2024 – Nov 27, 2024 I3C

lore
Share & tools
lore
#0 lore raw

devinfo is uninitialized if the condition is not satisfied, add an else condition to prevent unexpected behaviour.

The variable will contain an arbitrary value left from earlier computations in i3c_device_uevent.

---
 drivers/i3c/master.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/i3c/master.c +2 -0
index 42310c9a00c2..7594d3793eb0 100644
@@ -284,6 +284,8 @@ static int i3c_device_uevent(const struct device *dev, struct kobj_uevent_env *e
 
 	if (i3cdev->desc)
 		devinfo = i3cdev->desc->info;
+	else
+		return -ENODEV;
 	manuf = I3C_PID_MANUF_ID(devinfo.pid);
 	part = I3C_PID_PART_ID(devinfo.pid);
 	ext = I3C_PID_EXTRA_INFO(devinfo.pid);
Signature · 1 line
2.34.1
#1 lore raw

Hello,

I would really appreciate it if I could get some feedback on this patch, I would like to know if this approach is the right way to proceed.

Thanks and regards,
Advait

Quoted 28 lines · Advait Dhamorikar

devinfo is uninitialized if the condition is not satisfied, add an else condition to prevent unexpected behaviour.

The variable will contain an arbitrary value left from earlier computations in i3c_device_uevent.

---
 drivers/i3c/master.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/i3c/master.c +2 -1
index 42310c9a00c2..7594d3793eb0 100644
@@ -284,6 +284,8 @@ static int i3c_device_uevent(const struct device *dev, struct kobj_uevent_env *e
 
        if (i3cdev->desc)
                devinfo = i3cdev->desc->info;
+       else
+               return -ENODEV;
        manuf = I3C_PID_MANUF_ID(devinfo.pid);
        part = I3C_PID_PART_ID(devinfo.pid);
        ext = I3C_PID_EXTRA_INFO(devinfo.pid);
--

2.34.1

#2 lore raw
Quoted 5 lines · Advait Dhamorikar

Hello,

I would really appreciate it if I could get some feedback on this patch, I would like to know if this approach is the right way to proceed.

Yes and no, I don't think -ENODEV is allowed here, see platform_uevent and i2c_device_uevent.

Quoted 33 lines

Thanks and regards,
Advait

Quoted 28 lines · Advait Dhamorikar

devinfo is uninitialized if the condition is not satisfied, add an else condition to prevent unexpected behaviour.

The variable will contain an arbitrary value left from earlier computations in i3c_device_uevent.

---
 drivers/i3c/master.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/i3c/master.c +2 -1
index 42310c9a00c2..7594d3793eb0 100644
@@ -284,6 +284,8 @@ static int i3c_device_uevent(const struct device *dev, struct kobj_uevent_env *e
 
        if (i3cdev->desc)
                devinfo = i3cdev->desc->info;
+       else
+               return -ENODEV;
        manuf = I3C_PID_MANUF_ID(devinfo.pid);
        part = I3C_PID_PART_ID(devinfo.pid);
        ext = I3C_PID_EXTRA_INFO(devinfo.pid);
--

2.34.1

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#3 lore raw
Quoted 2 lines

Yes and no, I don't think -ENODEV is allowed here, see platform_uevent and i2c_device_uevent.

Thanks for the feedback. So if devinfo is uninitialized is it possible to initialize the i3c modalias using OF and ACPI uevent_modalias?

My humble apologies if this is a trivial question but I'm not really familiar with i3c and found the potential uninitialization using a static analyzer.

Thanks and regards,
Advait

Quoted 50 lines · Alexandre Belloni
Quoted 5 lines · Advait Dhamorikar

Hello,

I would really appreciate it if I could get some feedback on this patch, I would like to know if this approach is the right way to proceed.

Yes and no, I don't think -ENODEV is allowed here, see platform_uevent and i2c_device_uevent.

Quoted 23 lines

Thanks and regards,
Advait

Quoted 18 lines · Advait Dhamorikar

devinfo is uninitialized if the condition is not satisfied, add an else condition to prevent unexpected behaviour.

The variable will contain an arbitrary value left from earlier computations in i3c_device_uevent.

---
 drivers/i3c/master.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/i3c/master.c +0 -0
index 42310c9a00c2..7594d3793eb0 100644
@@ -284,6 +284,8 @@ static int i3c_device_uevent(const struct device *dev, struct kobj_uevent_env *e
 
Quoted 10 lines
Quoted 10 lines
drivers/i3c/master.c +2 -1
        if (i3cdev->desc)
                devinfo = i3cdev->desc->info;
+       else
+               return -ENODEV;
        manuf = I3C_PID_MANUF_ID(devinfo.pid);
        part = I3C_PID_PART_ID(devinfo.pid);
        ext = I3C_PID_EXTRA_INFO(devinfo.pid);
--

2.34.1

--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com