linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: dvb-frontends: Use kmemdup instead of duplicating its function
@ 2018-09-18 15:30 zhong jiang
  2018-09-18 19:58 ` Michael Ira Krufky
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: zhong jiang @ 2018-09-18 15:30 UTC (permalink / raw)
  To: mchehab; +Cc: brad, mkrufky, linux-media, linux-kernel

kmemdup has implemented the function that kmalloc() + memcpy().
We prefer to kmemdup rather than code opened implementation.

Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 drivers/media/dvb-frontends/lgdt3306a.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/dvb-frontends/lgdt3306a.c b/drivers/media/dvb-frontends/lgdt3306a.c
index 0e1f5da..abec2e5 100644
--- a/drivers/media/dvb-frontends/lgdt3306a.c
+++ b/drivers/media/dvb-frontends/lgdt3306a.c
@@ -2205,15 +2205,13 @@ static int lgdt3306a_probe(struct i2c_client *client,
 	struct dvb_frontend *fe;
 	int ret;
 
-	config = kzalloc(sizeof(struct lgdt3306a_config), GFP_KERNEL);
+	onfig = kmemdup(client->dev.platform_data,
+			sizeof(struct lgdt3306a_config), GFP_KERNEL);
 	if (config == NULL) {
 		ret = -ENOMEM;
 		goto fail;
 	}
 
-	memcpy(config, client->dev.platform_data,
-			sizeof(struct lgdt3306a_config));
-
 	config->i2c_addr = client->addr;
 	fe = lgdt3306a_attach(config, client->adapter);
 	if (fe == NULL) {
-- 
1.7.12.4


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] media: dvb-frontends: Use kmemdup instead of duplicating its function
  2018-09-18 15:30 [PATCH] media: dvb-frontends: Use kmemdup instead of duplicating its function zhong jiang
@ 2018-09-18 19:58 ` Michael Ira Krufky
  2018-09-19  1:30   ` zhong jiang
  2018-09-18 22:51 ` kbuild test robot
  2018-09-19  0:52 ` kbuild test robot
  2 siblings, 1 reply; 5+ messages in thread
From: Michael Ira Krufky @ 2018-09-18 19:58 UTC (permalink / raw)
  To: zhongjiang; +Cc: Mauro Carvalho Chehab, Brad Love, linux-media, LKML

On Tue, Sep 18, 2018 at 11:42 AM zhong jiang <zhongjiang@huawei.com> wrote:
>
> kmemdup has implemented the function that kmalloc() + memcpy().
> We prefer to kmemdup rather than code opened implementation.
>
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> ---
>  drivers/media/dvb-frontends/lgdt3306a.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/media/dvb-frontends/lgdt3306a.c b/drivers/media/dvb-frontends/lgdt3306a.c
> index 0e1f5da..abec2e5 100644
> --- a/drivers/media/dvb-frontends/lgdt3306a.c
> +++ b/drivers/media/dvb-frontends/lgdt3306a.c
> @@ -2205,15 +2205,13 @@ static int lgdt3306a_probe(struct i2c_client *client,
>         struct dvb_frontend *fe;
>         int ret;
>
> -       config = kzalloc(sizeof(struct lgdt3306a_config), GFP_KERNEL);
> +       onfig = kmemdup(client->dev.platform_data,
> +                       sizeof(struct lgdt3306a_config), GFP_KERNEL);
>         if (config == NULL) {
>                 ret = -ENOMEM;
>                 goto fail;
>         }
>
> -       memcpy(config, client->dev.platform_data,
> -                       sizeof(struct lgdt3306a_config));
> -
>         config->i2c_addr = client->addr;
>         fe = lgdt3306a_attach(config, client->adapter);
>         if (fe == NULL) {

Thank you for this patch, Zhong.  I suspect, however, that the patch
might contain a typo.  It looks like the `c` got dropped off of the
`config` variable.

Did you test this before sending it in?

Thanks again and best regards,

Michael Krufky

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] media: dvb-frontends: Use kmemdup instead of duplicating its function
  2018-09-18 15:30 [PATCH] media: dvb-frontends: Use kmemdup instead of duplicating its function zhong jiang
  2018-09-18 19:58 ` Michael Ira Krufky
@ 2018-09-18 22:51 ` kbuild test robot
  2018-09-19  0:52 ` kbuild test robot
  2 siblings, 0 replies; 5+ messages in thread
From: kbuild test robot @ 2018-09-18 22:51 UTC (permalink / raw)
  To: zhong jiang; +Cc: kbuild-all, mchehab, brad, mkrufky, linux-media, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3002 bytes --]

Hi zhong,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v4.19-rc4 next-20180918]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/zhong-jiang/media-dvb-frontends-Use-kmemdup-instead-of-duplicating-its-function/20180919-063244
base:   git://linuxtv.org/media_tree.git master
config: i386-randconfig-x002-201837 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   drivers/media/dvb-frontends/lgdt3306a.c: In function 'lgdt3306a_probe':
>> drivers/media/dvb-frontends/lgdt3306a.c:2208:2: error: 'onfig' undeclared (first use in this function); did you mean 'config'?
     onfig = kmemdup(client->dev.platform_data,
     ^~~~~
     config
   drivers/media/dvb-frontends/lgdt3306a.c:2208:2: note: each undeclared identifier is reported only once for each function it appears in

vim +2208 drivers/media/dvb-frontends/lgdt3306a.c

  2199	
  2200	static int lgdt3306a_probe(struct i2c_client *client,
  2201			const struct i2c_device_id *id)
  2202	{
  2203		struct lgdt3306a_config *config;
  2204		struct lgdt3306a_state *state;
  2205		struct dvb_frontend *fe;
  2206		int ret;
  2207	
> 2208		onfig = kmemdup(client->dev.platform_data,
  2209				sizeof(struct lgdt3306a_config), GFP_KERNEL);
  2210		if (config == NULL) {
  2211			ret = -ENOMEM;
  2212			goto fail;
  2213		}
  2214	
  2215		config->i2c_addr = client->addr;
  2216		fe = lgdt3306a_attach(config, client->adapter);
  2217		if (fe == NULL) {
  2218			ret = -ENODEV;
  2219			goto err_fe;
  2220		}
  2221	
  2222		i2c_set_clientdata(client, fe->demodulator_priv);
  2223		state = fe->demodulator_priv;
  2224		state->frontend.ops.release = NULL;
  2225	
  2226		/* create mux i2c adapter for tuner */
  2227		state->muxc = i2c_mux_alloc(client->adapter, &client->dev,
  2228					  1, 0, I2C_MUX_LOCKED,
  2229					  lgdt3306a_select, lgdt3306a_deselect);
  2230		if (!state->muxc) {
  2231			ret = -ENOMEM;
  2232			goto err_kfree;
  2233		}
  2234		state->muxc->priv = client;
  2235		ret = i2c_mux_add_adapter(state->muxc, 0, 0, 0);
  2236		if (ret)
  2237			goto err_kfree;
  2238	
  2239		/* create dvb_frontend */
  2240		fe->ops.i2c_gate_ctrl = NULL;
  2241		*config->i2c_adapter = state->muxc->adapter[0];
  2242		*config->fe = fe;
  2243	
  2244		dev_info(&client->dev, "LG Electronics LGDT3306A successfully identified\n");
  2245	
  2246		return 0;
  2247	
  2248	err_kfree:
  2249		kfree(state);
  2250	err_fe:
  2251		kfree(config);
  2252	fail:
  2253		dev_warn(&client->dev, "probe failed = %d\n", ret);
  2254		return ret;
  2255	}
  2256	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 33883 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] media: dvb-frontends: Use kmemdup instead of duplicating its function
  2018-09-18 15:30 [PATCH] media: dvb-frontends: Use kmemdup instead of duplicating its function zhong jiang
  2018-09-18 19:58 ` Michael Ira Krufky
  2018-09-18 22:51 ` kbuild test robot
@ 2018-09-19  0:52 ` kbuild test robot
  2 siblings, 0 replies; 5+ messages in thread
From: kbuild test robot @ 2018-09-19  0:52 UTC (permalink / raw)
  To: zhong jiang; +Cc: kbuild-all, mchehab, brad, mkrufky, linux-media, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2987 bytes --]

Hi zhong,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v4.19-rc4 next-20180918]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/zhong-jiang/media-dvb-frontends-Use-kmemdup-instead-of-duplicating-its-function/20180919-063244
base:   git://linuxtv.org/media_tree.git master
config: x86_64-randconfig-s2-09190757 (attached as .config)
compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   drivers/media/dvb-frontends/lgdt3306a.c: In function 'lgdt3306a_probe':
>> drivers/media/dvb-frontends/lgdt3306a.c:2208:2: error: 'onfig' undeclared (first use in this function)
     onfig = kmemdup(client->dev.platform_data,
     ^~~~~
   drivers/media/dvb-frontends/lgdt3306a.c:2208:2: note: each undeclared identifier is reported only once for each function it appears in

vim +/onfig +2208 drivers/media/dvb-frontends/lgdt3306a.c

  2199	
  2200	static int lgdt3306a_probe(struct i2c_client *client,
  2201			const struct i2c_device_id *id)
  2202	{
  2203		struct lgdt3306a_config *config;
  2204		struct lgdt3306a_state *state;
  2205		struct dvb_frontend *fe;
  2206		int ret;
  2207	
> 2208		onfig = kmemdup(client->dev.platform_data,
  2209				sizeof(struct lgdt3306a_config), GFP_KERNEL);
  2210		if (config == NULL) {
  2211			ret = -ENOMEM;
  2212			goto fail;
  2213		}
  2214	
  2215		config->i2c_addr = client->addr;
  2216		fe = lgdt3306a_attach(config, client->adapter);
  2217		if (fe == NULL) {
  2218			ret = -ENODEV;
  2219			goto err_fe;
  2220		}
  2221	
  2222		i2c_set_clientdata(client, fe->demodulator_priv);
  2223		state = fe->demodulator_priv;
  2224		state->frontend.ops.release = NULL;
  2225	
  2226		/* create mux i2c adapter for tuner */
  2227		state->muxc = i2c_mux_alloc(client->adapter, &client->dev,
  2228					  1, 0, I2C_MUX_LOCKED,
  2229					  lgdt3306a_select, lgdt3306a_deselect);
  2230		if (!state->muxc) {
  2231			ret = -ENOMEM;
  2232			goto err_kfree;
  2233		}
  2234		state->muxc->priv = client;
  2235		ret = i2c_mux_add_adapter(state->muxc, 0, 0, 0);
  2236		if (ret)
  2237			goto err_kfree;
  2238	
  2239		/* create dvb_frontend */
  2240		fe->ops.i2c_gate_ctrl = NULL;
  2241		*config->i2c_adapter = state->muxc->adapter[0];
  2242		*config->fe = fe;
  2243	
  2244		dev_info(&client->dev, "LG Electronics LGDT3306A successfully identified\n");
  2245	
  2246		return 0;
  2247	
  2248	err_kfree:
  2249		kfree(state);
  2250	err_fe:
  2251		kfree(config);
  2252	fail:
  2253		dev_warn(&client->dev, "probe failed = %d\n", ret);
  2254		return ret;
  2255	}
  2256	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 33059 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] media: dvb-frontends: Use kmemdup instead of duplicating its function
  2018-09-18 19:58 ` Michael Ira Krufky
@ 2018-09-19  1:30   ` zhong jiang
  0 siblings, 0 replies; 5+ messages in thread
From: zhong jiang @ 2018-09-19  1:30 UTC (permalink / raw)
  To: Michael Ira Krufky; +Cc: Mauro Carvalho Chehab, Brad Love, linux-media, LKML

On 2018/9/19 3:58, Michael Ira Krufky wrote:
> On Tue, Sep 18, 2018 at 11:42 AM zhong jiang <zhongjiang@huawei.com> wrote:
>> kmemdup has implemented the function that kmalloc() + memcpy().
>> We prefer to kmemdup rather than code opened implementation.
>>
>> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
>> ---
>>  drivers/media/dvb-frontends/lgdt3306a.c | 6 ++----
>>  1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/media/dvb-frontends/lgdt3306a.c b/drivers/media/dvb-frontends/lgdt3306a.c
>> index 0e1f5da..abec2e5 100644
>> --- a/drivers/media/dvb-frontends/lgdt3306a.c
>> +++ b/drivers/media/dvb-frontends/lgdt3306a.c
>> @@ -2205,15 +2205,13 @@ static int lgdt3306a_probe(struct i2c_client *client,
>>         struct dvb_frontend *fe;
>>         int ret;
>>
>> -       config = kzalloc(sizeof(struct lgdt3306a_config), GFP_KERNEL);
>> +       onfig = kmemdup(client->dev.platform_data,
>> +                       sizeof(struct lgdt3306a_config), GFP_KERNEL);
>>         if (config == NULL) {
>>                 ret = -ENOMEM;
>>                 goto fail;
>>         }
>>
>> -       memcpy(config, client->dev.platform_data,
>> -                       sizeof(struct lgdt3306a_config));
>> -
>>         config->i2c_addr = client->addr;
>>         fe = lgdt3306a_attach(config, client->adapter);
>>         if (fe == NULL) {
> Thank you for this patch, Zhong.  I suspect, however, that the patch
> might contain a typo.  It looks like the `c` got dropped off of the
> `config` variable.
I am sorry.  It's my fault.:-[ . Will repost

Thanks,
zhong jiang
> Did you test this before sending it in?
>
> Thanks again and best regards,
>
> Michael Krufky
>
> .
>



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-09-19  1:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-18 15:30 [PATCH] media: dvb-frontends: Use kmemdup instead of duplicating its function zhong jiang
2018-09-18 19:58 ` Michael Ira Krufky
2018-09-19  1:30   ` zhong jiang
2018-09-18 22:51 ` kbuild test robot
2018-09-19  0:52 ` kbuild test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).