Commit ce7c637a authored by Julia Lawall's avatar Julia Lawall Committed by Jonathan Cameron

iio: potentiometer: merge calls to of_match_device and of_device_get_match_data

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: default avatarJulia Lawall <Julia.Lawall@lip6.fr>
Reviewed-by: default avatarPeter Rosin <peda@axentia.se>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 892e62fa
...@@ -137,7 +137,6 @@ static int max5481_probe(struct spi_device *spi) ...@@ -137,7 +137,6 @@ static int max5481_probe(struct spi_device *spi)
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct max5481_data *data; struct max5481_data *data;
const struct spi_device_id *id = spi_get_device_id(spi); const struct spi_device_id *id = spi_get_device_id(spi);
const struct of_device_id *match;
int ret; int ret;
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data)); indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data));
...@@ -149,10 +148,8 @@ static int max5481_probe(struct spi_device *spi) ...@@ -149,10 +148,8 @@ static int max5481_probe(struct spi_device *spi)
data->spi = spi; data->spi = spi;
match = of_match_device(of_match_ptr(max5481_match), &spi->dev); data->cfg = of_device_get_match_data(&spi->dev);
if (match) if (!data->cfg)
data->cfg = of_device_get_match_data(&spi->dev);
else
data->cfg = &max5481_cfg[id->driver_data]; data->cfg = &max5481_cfg[id->driver_data];
indio_dev->name = id->name; indio_dev->name = id->name;
......
...@@ -147,7 +147,6 @@ static int mcp4018_probe(struct i2c_client *client) ...@@ -147,7 +147,6 @@ static int mcp4018_probe(struct i2c_client *client)
struct device *dev = &client->dev; struct device *dev = &client->dev;
struct mcp4018_data *data; struct mcp4018_data *data;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
const struct of_device_id *match;
if (!i2c_check_functionality(client->adapter, if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_BYTE)) { I2C_FUNC_SMBUS_BYTE)) {
...@@ -162,10 +161,8 @@ static int mcp4018_probe(struct i2c_client *client) ...@@ -162,10 +161,8 @@ static int mcp4018_probe(struct i2c_client *client)
i2c_set_clientdata(client, indio_dev); i2c_set_clientdata(client, indio_dev);
data->client = client; data->client = client;
match = of_match_device(of_match_ptr(mcp4018_of_match), dev); data->cfg = of_device_get_match_data(dev);
if (match) if (!data->cfg)
data->cfg = of_device_get_match_data(dev);
else
data->cfg = &mcp4018_cfg[i2c_match_id(mcp4018_id, client)->driver_data]; data->cfg = &mcp4018_cfg[i2c_match_id(mcp4018_id, client)->driver_data];
indio_dev->dev.parent = dev; indio_dev->dev.parent = dev;
......
...@@ -360,7 +360,6 @@ static int mcp4531_probe(struct i2c_client *client) ...@@ -360,7 +360,6 @@ static int mcp4531_probe(struct i2c_client *client)
struct device *dev = &client->dev; struct device *dev = &client->dev;
struct mcp4531_data *data; struct mcp4531_data *data;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
const struct of_device_id *match;
if (!i2c_check_functionality(client->adapter, if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_WORD_DATA)) { I2C_FUNC_SMBUS_WORD_DATA)) {
...@@ -375,10 +374,8 @@ static int mcp4531_probe(struct i2c_client *client) ...@@ -375,10 +374,8 @@ static int mcp4531_probe(struct i2c_client *client)
i2c_set_clientdata(client, indio_dev); i2c_set_clientdata(client, indio_dev);
data->client = client; data->client = client;
match = of_match_device(of_match_ptr(mcp4531_of_match), dev); data->cfg = of_device_get_match_data(dev);
if (match) if (!data->cfg)
data->cfg = of_device_get_match_data(dev);
else
data->cfg = &mcp4531_cfg[i2c_match_id(mcp4531_id, client)->driver_data]; data->cfg = &mcp4531_cfg[i2c_match_id(mcp4531_id, client)->driver_data];
indio_dev->dev.parent = dev; indio_dev->dev.parent = dev;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment