diff mbox series

[linux,dev-5.4,2/2] i2c: fsi: Prevent adding adapters for ports without dts nodes

Message ID 20200519193936.7295-3-eajames@linux.ibm.com
State Accepted, archived
Headers show
Series i2c: fsi: Fixes for systems with more ports | expand

Commit Message

Eddie James May 19, 2020, 7:39 p.m. UTC
Ports should be defined in the devicetree if they are to be enabled on
the system.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
 drivers/i2c/busses/i2c-fsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Joel Stanley June 2, 2020, 1:57 a.m. UTC | #1
On Tue, 19 May 2020 at 19:39, Eddie James <eajames@linux.ibm.com> wrote:
>
> Ports should be defined in the devicetree if they are to be enabled on
> the system.
>
> Signed-off-by: Eddie James <eajames@linux.ibm.com>
> ---
>  drivers/i2c/busses/i2c-fsi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c
> index 977d6f524649..d6ea502521a5 100644
> --- a/drivers/i2c/busses/i2c-fsi.c
> +++ b/drivers/i2c/busses/i2c-fsi.c
> @@ -703,7 +703,7 @@ static int fsi_i2c_probe(struct device *dev)
>
>         for (port_no = 0; port_no < ports; port_no++) {
>                 np = fsi_i2c_find_port_of_node(dev->of_node, port_no);
> -               if (np && !of_device_is_available(np))
> +               if (!np || !of_device_is_available(np))

I thought this was wrong, but the important part is that
of_device_is_available() returns true if it can't find the status
property (ie np is null), so we need to check for np being NULL, and
if that's false we can check if it's "available".

We could write it like this if you agree it's clearer:

if (!np)
   /* Port not defined in device tree */
   continue;
if (of_device_is_available())
   continue;

Or I can take your patch as-is. Let me know.

Cheers,

Joel




>                         continue;
>
>                 port = kzalloc(sizeof(*port), GFP_KERNEL);
> --
> 2.24.0
>
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c
index 977d6f524649..d6ea502521a5 100644
--- a/drivers/i2c/busses/i2c-fsi.c
+++ b/drivers/i2c/busses/i2c-fsi.c
@@ -703,7 +703,7 @@  static int fsi_i2c_probe(struct device *dev)
 
 	for (port_no = 0; port_no < ports; port_no++) {
 		np = fsi_i2c_find_port_of_node(dev->of_node, port_no);
-		if (np && !of_device_is_available(np))
+		if (!np || !of_device_is_available(np))
 			continue;
 
 		port = kzalloc(sizeof(*port), GFP_KERNEL);