gpio: max732x: add error handling for i2c_new_dummy
authorZhouyang Jia <jiazhouyang09@gmail.com>
Tue, 12 Jun 2018 03:28:52 +0000 (11:28 +0800)
committerLinus Walleij <linus.walleij@linaro.org>
Mon, 18 Jun 2018 05:55:30 +0000 (07:55 +0200)
When i2c_new_dummy fails, the lack of error-handling code may
cause unexpected results.

This patch adds error-handling code after calling i2c_new_dummy.

Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpio-max732x.c

index 9d8bcc69f2454439feb901bfa7274651d3fbbcb1..f03cb0ba7726fb2776fce558b07cd4bfc81df6ed 100644 (file)
@@ -653,6 +653,12 @@ static int max732x_probe(struct i2c_client *client,
                chip->client_group_a = client;
                if (nr_port > 8) {
                        c = i2c_new_dummy(client->adapter, addr_b);
+                       if (!c) {
+                               dev_err(&client->dev,
+                                       "Failed to allocate I2C device\n");
+                               ret = -ENODEV;
+                               goto out_failed;
+                       }
                        chip->client_group_b = chip->client_dummy = c;
                }
                break;
@@ -660,6 +666,12 @@ static int max732x_probe(struct i2c_client *client,
                chip->client_group_b = client;
                if (nr_port > 8) {
                        c = i2c_new_dummy(client->adapter, addr_a);
+                       if (!c) {
+                               dev_err(&client->dev,
+                                       "Failed to allocate I2C device\n");
+                               ret = -ENODEV;
+                               goto out_failed;
+                       }
                        chip->client_group_a = chip->client_dummy = c;
                }
                break;