diff mbox series

[PATCH-next] i3c: master: Fix potentially uninit variable

Message ID 20241119153941.8307-1-advaitdhamorikar@gmail.com (mailing list archive)
State New
Headers show
Series [PATCH-next] i3c: master: Fix potentially uninit variable | expand

Commit Message

Advait Dhamorikar Nov. 19, 2024, 3:39 p.m. UTC
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`.

Signed-off-by: Advait Dhamorikar <advaitdhamorikar@gmail.com>
---
 drivers/i3c/master.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Alexandre Belloni Nov. 26, 2024, 10:48 p.m. UTC | #1
On 27/11/2024 01:26:08+0530, Advait Dhamorikar wrote:
> 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.


> Thanks and regards,
> Advait
> 
> On Tue, 19 Nov 2024 at 21:09, Advait Dhamorikar
> <advaitdhamorikar@gmail.com> wrote:
> >
> > 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`.
> >
> > Signed-off-by: Advait Dhamorikar <advaitdhamorikar@gmail.com>
> > ---
> >  drivers/i3c/master.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> > index 42310c9a00c2..7594d3793eb0 100644
> > --- a/drivers/i3c/master.c
> > +++ b/drivers/i3c/master.c
> > @@ -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
> >
diff mbox series

Patch

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 42310c9a00c2..7594d3793eb0 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -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);