2019-11-06 21:24:33

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 00/17] media: use new API for creating client devices

These media drivers create a new I2C client device with the deprecated
i2c_new_device() and check afterwards if the client exists and if a
driver is bound to it.

These series changes the drivers to use the now suggested
i2c_new_client_device() call and introduces a helper to check if the
driver is bound. This helper supports (for now) the old and the new API
and is also more readable.

The drivers were converted with the following coccinelle script:

@@
expression client;
statement S;
@@
client =
- i2c_new_device
+ i2c_new_client_device
(...);
... when != client
if (
- \( !client \| client == NULL \) || \( !client->dev.driver \| client->dev.driver == NULL \)
+ !i2c_client_has_driver(client)
) {
S
}

The helper has been tested on a Renesas Salvator-XS board (R-Car M3-N).
The rest was build tested by me. buildbot has this still queued.

Although the first patch is in the I2C realm, I suggest that all patches
go through the media tree to avoid the dependency. There are no merge
conflicts with I2C currently and I don't see any coming (famous last
words).

This series is based on linux-next as of today. It does not depend on
the i2c_new_probed_device() conversion I sent out earlier today. This
series can be applied as is.

Looking forward to comments.

Thanks and happy hacking,

Wolfram


Wolfram Sang (17):
i2c: add helper to check if a client has a driver attached
media: dvb-core: dvbdev: convert to use i2c_new_client_device()
media: dvb-frontends: cxd2820r_core: convert to use
i2c_new_client_device()
media: dvb-frontends: lgdt330x: convert to use i2c_new_client_device()
media: dvb-frontends: m88ds3103: convert to use
i2c_new_client_device()
media: dvb-frontends: ts2020: convert to use i2c_new_client_device()
media: pci: cx23885: cx23885-dvb: convert to use
i2c_new_client_device()
media: pci: saa7164: saa7164-dvb: convert to use
i2c_new_client_device()
media: pci: smipcie: smipcie-main: convert to use
i2c_new_client_device()
media: platform: sti: c8sectpfe: c8sectpfe-dvb: convert to use
i2c_new_client_device()
media: usb: dvb-usb-v2: af9035: convert to use i2c_new_client_device()
media: usb: dvb-usb-v2: anysee: convert to use i2c_new_client_device()
media: usb: dvb-usb-v2: rtl28xxu: convert to use
i2c_new_client_device()
media: usb: dvb-usb-v2: zd1301: convert to use i2c_new_client_device()
media: usb: dvb-usb: dib0700_devices: convert to use
i2c_new_client_device()
media: usb: dvb-usb: dw2102: convert to use i2c_new_client_device()
media: v4l2-core: v4l2-i2c: convert to use i2c_new_client_device()

drivers/media/dvb-core/dvbdev.c | 4 +-
drivers/media/dvb-frontends/cxd2820r_core.c | 4 +-
drivers/media/dvb-frontends/lgdt330x.c | 4 +-
drivers/media/dvb-frontends/m88ds3103.c | 4 +-
drivers/media/dvb-frontends/ts2020.c | 4 +-
drivers/media/pci/cx23885/cx23885-dvb.c | 114 +++++++++---------
drivers/media/pci/saa7164/saa7164-dvb.c | 20 +--
drivers/media/pci/smipcie/smipcie-main.c | 4 +-
.../platform/sti/c8sectpfe/c8sectpfe-dvb.c | 4 +-
drivers/media/usb/dvb-usb-v2/af9035.c | 4 +-
drivers/media/usb/dvb-usb-v2/anysee.c | 4 +-
drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 36 +++---
drivers/media/usb/dvb-usb-v2/zd1301.c | 4 +-
drivers/media/usb/dvb-usb/dib0700_devices.c | 8 +-
drivers/media/usb/dvb-usb/dw2102.c | 8 +-
drivers/media/v4l2-core/v4l2-i2c.c | 2 +-
include/linux/i2c.h | 5 +
17 files changed, 116 insertions(+), 117 deletions(-)

--
2.20.1


2019-11-06 21:24:38

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 01/17] i2c: add helper to check if a client has a driver attached

Factoring out something used in the media subsystem. As an improvement,
it bails out on both, NULL and ERRPTR.

Signed-off-by: Wolfram Sang <[email protected]>
---
include/linux/i2c.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index aaf57d9b41db..93b315c9a062 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -850,6 +850,11 @@ extern void i2c_del_driver(struct i2c_driver *driver);
#define i2c_add_driver(driver) \
i2c_register_driver(THIS_MODULE, driver)

+static inline bool i2c_client_has_driver(struct i2c_client *client)
+{
+ return !IS_ERR_OR_NULL(client) && client->dev.driver;
+}
+
extern struct i2c_client *i2c_use_client(struct i2c_client *client);
extern void i2c_release_client(struct i2c_client *client);

--
2.20.1

2019-11-06 21:26:02

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 09/17] media: pci: smipcie: smipcie-main: convert to use i2c_new_client_device()

Use the newer API returning an ERRPTR and use the new helper to bail
out.

Signed-off-by: Wolfram Sang <[email protected]>
---
drivers/media/pci/smipcie/smipcie-main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/pci/smipcie/smipcie-main.c b/drivers/media/pci/smipcie/smipcie-main.c
index 1fb78462e081..9ca0fc3e6f80 100644
--- a/drivers/media/pci/smipcie/smipcie-main.c
+++ b/drivers/media/pci/smipcie/smipcie-main.c
@@ -484,8 +484,8 @@ static struct i2c_client *smi_add_i2c_client(struct i2c_adapter *adapter,
struct i2c_client *client;

request_module(info->type);
- client = i2c_new_device(adapter, info);
- if (client == NULL || client->dev.driver == NULL)
+ client = i2c_new_client_device(adapter, info);
+ if (!i2c_client_has_driver(client))
goto err_add_i2c_client;

if (!try_module_get(client->dev.driver->owner)) {
--
2.20.1

2019-11-06 21:26:02

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 06/17] media: dvb-frontends: ts2020: convert to use i2c_new_client_device()

Use the newer API returning an ERRPTR and use the new helper to bail
out.

Signed-off-by: Wolfram Sang <[email protected]>
---
drivers/media/dvb-frontends/ts2020.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/ts2020.c b/drivers/media/dvb-frontends/ts2020.c
index 6c24d6d0d4c9..234607b02edb 100644
--- a/drivers/media/dvb-frontends/ts2020.c
+++ b/drivers/media/dvb-frontends/ts2020.c
@@ -519,8 +519,8 @@ struct dvb_frontend *ts2020_attach(struct dvb_frontend *fe,
strscpy(board_info.type, "ts2020", I2C_NAME_SIZE);
board_info.addr = config->tuner_address;
board_info.platform_data = &pdata;
- client = i2c_new_device(i2c, &board_info);
- if (!client || !client->dev.driver)
+ client = i2c_new_client_device(i2c, &board_info);
+ if (!i2c_client_has_driver(client))
return NULL;

return fe;
--
2.20.1

2019-11-06 21:26:35

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 03/17] media: dvb-frontends: cxd2820r_core: convert to use i2c_new_client_device()

Use the newer API returning an ERRPTR and use the new helper to bail
out.

Signed-off-by: Wolfram Sang <[email protected]>
---
drivers/media/dvb-frontends/cxd2820r_core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/cxd2820r_core.c b/drivers/media/dvb-frontends/cxd2820r_core.c
index d137199e13e6..b1618339eec0 100644
--- a/drivers/media/dvb-frontends/cxd2820r_core.c
+++ b/drivers/media/dvb-frontends/cxd2820r_core.c
@@ -530,8 +530,8 @@ struct dvb_frontend *cxd2820r_attach(const struct cxd2820r_config *config,
strscpy(board_info.type, "cxd2820r", I2C_NAME_SIZE);
board_info.addr = config->i2c_address;
board_info.platform_data = &pdata;
- client = i2c_new_device(adapter, &board_info);
- if (!client || !client->dev.driver)
+ client = i2c_new_client_device(adapter, &board_info);
+ if (!i2c_client_has_driver(client))
return NULL;

return pdata.get_dvb_frontend(client);
--
2.20.1

2019-11-06 21:26:42

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 02/17] media: dvb-core: dvbdev: convert to use i2c_new_client_device()

Use the newer API returning an ERRPTR and use the new helper to bail
out.

Signed-off-by: Wolfram Sang <[email protected]>
---
drivers/media/dvb-core/dvbdev.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 917fe034af37..80b6a71aa33e 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -983,8 +983,8 @@ struct i2c_client *dvb_module_probe(const char *module_name,
board_info->addr = addr;
board_info->platform_data = platform_data;
request_module(module_name);
- client = i2c_new_device(adap, board_info);
- if (client == NULL || client->dev.driver == NULL) {
+ client = i2c_new_client_device(adap, board_info);
+ if (!i2c_client_has_driver(client)) {
kfree(board_info);
return NULL;
}
--
2.20.1

2019-12-11 08:00:01

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH 01/17] i2c: add helper to check if a client has a driver attached

On Wed, Nov 06, 2019 at 10:21:01PM +0100, Wolfram Sang wrote:
> Factoring out something used in the media subsystem. As an improvement,
> it bails out on both, NULL and ERRPTR.
>
> Signed-off-by: Wolfram Sang <[email protected]>

I picked it up myself now, so we can start using it right away.

Applied to for-current, thanks!


Attachments:
(No filename) (354.00 B)
signature.asc (849.00 B)
Download all attachments