i2c: mux: pca954x: merge calls to of_match_device and of_device_get_match_data
authorJulia Lawall <Julia.Lawall@lip6.fr>
Mon, 21 May 2018 09:49:08 +0000 (11:49 +0200)
committerPeter Rosin <peda@axentia.se>
Thu, 24 May 2018 11:51:25 +0000 (13:51 +0200)
Drop call to of_match_device, which is subsumed by the subsequent
call to of_device_get_match_data.  The code becomes simpler, and a
temporary variable can be dropped.

The semantic match that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
local idexpression match;
identifier i;
expression x, dev, e, e1;
@@
-        match@i = of_match_device(x, dev);
-        if (match) e = of_device_get_match_data(dev);
-        else e = e1;
+        e = of_device_get_match_data(dev);
+        if (!e) e = e1;

@@
identifier r.i;
@@
- const struct of_device_id *i;
... when != i
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Peter Rosin <peda@axentia.se>
drivers/i2c/muxes/i2c-mux-pca954x.c

index fe20b8ec52474786c87065df64127c1edc81c0cb..fbc748027087dbfd9783a459ccc74a7834d1a480 100644 (file)
@@ -374,7 +374,6 @@ static int pca954x_probe(struct i2c_client *client,
        int num, force, class;
        struct i2c_mux_core *muxc;
        struct pca954x *data;
-       const struct of_device_id *match;
        int ret;
 
        if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE))
@@ -401,10 +400,8 @@ static int pca954x_probe(struct i2c_client *client,
                udelay(1);
        }
 
-       match = of_match_device(of_match_ptr(pca954x_of_match), &client->dev);
-       if (match)
-               data->chip = of_device_get_match_data(&client->dev);
-       else
+       data->chip = of_device_get_match_data(&client->dev);
+       if (!data->chip)
                data->chip = &chips[id->driver_data];
 
        if (data->chip->id.manufacturer_id != I2C_DEVICE_ID_NONE) {