linux-i3c.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i3c: fix uninitialized variable use in i2c setup
@ 2022-03-08 13:42 Jamie Iles
  2022-03-08 15:11 ` Alexandre Belloni
  0 siblings, 1 reply; 2+ messages in thread
From: Jamie Iles @ 2022-03-08 13:42 UTC (permalink / raw)
  To: linux-i3c; +Cc: Jamie Iles, kernel test robot, Alexandre Belloni

97a82882d852 ("i3c: remove i2c board info from i2c_dev_desc") removed
the boardinfo from i2c_dev_desc to decouple device enumeration from
setup but did not correctly lookup the i2c_dev_desc to store the new
device, instead dereferencing an uninitialized variable.

Lookup the device that has already been registered by address to store
the i2c client device.

Fixes: 97a82882d852 ("i3c: remove i2c board info from i2c_dev_desc")
Reported-by: kernel test robot <lkp@intel.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Jamie Iles <quic_jiles@quicinc.com>
---
 drivers/i3c/master.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index db0fa6887eef..f0bdecd7940f 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -2318,8 +2318,13 @@ static int i3c_master_i2c_adapter_init(struct i3c_master_controller *master)
 	 * We silently ignore failures here. The bus should keep working
 	 * correctly even if one or more i2c devices are not registered.
 	 */
-	list_for_each_entry(i2cboardinfo, &master->boardinfo.i2c, node)
+	list_for_each_entry(i2cboardinfo, &master->boardinfo.i2c, node) {
+		i2cdev = i3c_master_find_i2c_dev_by_addr(master,
+							 i2cboardinfo->base.addr);
+		if (WARN_ON(!i2cdev))
+			continue;
 		i2cdev->dev = i2c_new_client_device(adap, &i2cboardinfo->base);
+	}
 
 	return 0;
 }
-- 
2.32.0


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* Re: [PATCH] i3c: fix uninitialized variable use in i2c setup
  2022-03-08 13:42 [PATCH] i3c: fix uninitialized variable use in i2c setup Jamie Iles
@ 2022-03-08 15:11 ` Alexandre Belloni
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Belloni @ 2022-03-08 15:11 UTC (permalink / raw)
  To: Jamie Iles; +Cc: linux-i3c, kernel test robot

On 08/03/2022 13:42:26+0000, Jamie Iles wrote:
> 97a82882d852 ("i3c: remove i2c board info from i2c_dev_desc") removed
> the boardinfo from i2c_dev_desc to decouple device enumeration from
> setup but did not correctly lookup the i2c_dev_desc to store the new
> device, instead dereferencing an uninitialized variable.
> 
> Lookup the device that has already been registered by address to store
> the i2c client device.
> 
> Fixes: 97a82882d852 ("i3c: remove i2c board info from i2c_dev_desc")
> Reported-by: kernel test robot <lkp@intel.com>
> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
> Signed-off-by: Jamie Iles <quic_jiles@quicinc.com>
> ---
>  drivers/i3c/master.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
Applied, thanks.

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

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

end of thread, other threads:[~2022-03-09 16:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 13:42 [PATCH] i3c: fix uninitialized variable use in i2c setup Jamie Iles
2022-03-08 15:11 ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).