Skip to contentSkip to conversation

staging: media: cxd2099: use kzalloc to allocate ci pointer of type struct cxd in cxd2099_attach

PATCH In review Devendra Naga 2 participants 5 messages Aug 4, 2012 – Aug 5, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 staging: media: cxd2099: use kzalloc to allocate ci pointer of type struct cxd in cxd2099_attach

this does kmalloc and followed by memset, calling kzalloc will actually sets the allocated memory to zero, use kzalloc instead

---
 drivers/staging/media/cxd2099/cxd2099.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/media/cxd2099/cxd2099.c +1 -2
index 1678503..4f2235f 100644
@@ -691,10 +691,9 @@ struct dvb_ca_en50221 *cxd2099_attach(struct cxd2099_cfg *cfg,
 		return NULL;
 	}
 
-	ci = kmalloc(sizeof(struct cxd), GFP_KERNEL);
+	ci = kzalloc(sizeof(struct cxd), GFP_KERNEL);
 	if (!ci)
 		return NULL;
-	memset(ci, 0, sizeof(*ci));
 
 	mutex_init(&ci->lock);
 	memcpy(&ci->cfg, cfg, sizeof(struct cxd2099_cfg));
Signature · 1 line
1.7.9.5
#1 lore raw

Hi Devendra,

Quoted 3 lines · Devendra Naga
        mutex_init(&ci->lock);
        memcpy(&ci->cfg, cfg, sizeof(struct cxd2099_cfg));

While you're still looking at this driver, perhaps you can change the memcpy with a plain struct assignment (if you feel like).
It's really pointless to use a memcpy here.

Something like this:

- memcpy(&ci->cfg, cfg, sizeof(struct cxd2099_cfg));
+ ci->cfg = *cfg;

Regards,
Ezequiel.

#2 lore raw

Hello Ezequiel,

Quoted 15 lines · Ezequiel Garcia

Hi Devendra,

Quoted 3 lines · Devendra Naga
        mutex_init(&ci->lock);
        memcpy(&ci->cfg, cfg, sizeof(struct cxd2099_cfg));

While you're still looking at this driver, perhaps you can change the memcpy with a plain struct assignment (if you feel like).
It's really pointless to use a memcpy here.

Something like this:

Review

Quoted 2 lines
(quoted diff) +1 -1
-       memcpy(&ci->cfg, cfg, sizeof(struct cxd2099_cfg));
+       ci->cfg = *cfg;

Correct, and also one more thing like this is

- memcpy(&ci->en, &en_templ, sizeof(en_templ));
+ ci->en = en_templ;

Is it ok if i change ci->cfg and ci->en?

Quoted 2 lines

Regards,
Ezequiel.

Thanks,

#3 lore raw

Hi Devendra,

Quoted 25 lines · Devendra Naga

Hello Ezequiel,

Quoted 15 lines · Ezequiel Garcia

Hi Devendra,

Quoted 3 lines · Devendra Naga
        mutex_init(&ci->lock);
        memcpy(&ci->cfg, cfg, sizeof(struct cxd2099_cfg));

While you're still looking at this driver, perhaps you can change the memcpy with a plain struct assignment (if you feel like).
It's really pointless to use a memcpy here.

Something like this:

Review

Quoted 2 lines
(quoted diff) +1 -1
-       memcpy(&ci->cfg, cfg, sizeof(struct cxd2099_cfg));
+       ci->cfg = *cfg;

Correct, and also one more thing like this is

(quoted diff) +1 -1
-           memcpy(&ci->en, &en_templ, sizeof(en_templ));
+          ci->en = en_templ;
Quoted 1 line

Is it ok if i change ci->cfg and ci->en?

Yes, I believe it is ok.

A few more remarks I would like to add.

1. When sending patches for staging/media, it's not necessary to put staging list/maintainer
(Greg) on Cc. I guess, it doesn't hurt, though.
But it's media list / Mauro who will decide on the patches.

2. You could also change the order in "struct cxd". Currently it's like this

struct cxd {
        struct dvb_ca_en50221 en;
        struct i2c_adapter *i2c;
        struct cxd2099_cfg cfg;

But it would be better to put it like this

struct cxd {
        struct i2c_adapter *i2c;
        struct cxd2099_cfg cfg;
        struct dvb_ca_en50221 en;

It's more logical, and ci->i2c and ci->cfg are used more frequently, so it makes sense to put it near the top of the struct.
(You may think I'm being too paranoid: I am).

3. You don't have hw to test, uh?
In that case, don't forget to always add a "Tested by compilation only" inside the commit message. That way the maintainer (Mauro) are free to _not_ pick
the patch, if he feels it's not safe/clear enough.

Hope this helps and thanks for your work,
Ezequiel.

#4 lore raw

Hello Ezequiel,

Thanks, you wrote a full description of what i need to do.. i will definitely follow this.

Quoted 31 lines · Ezequiel Garcia

Hi Devendra,

Quoted 25 lines · Devendra Naga

Hello Ezequiel,

Quoted 15 lines · Ezequiel Garcia

Hi Devendra,

Quoted 3 lines · Devendra Naga
        mutex_init(&ci->lock);
        memcpy(&ci->cfg, cfg, sizeof(struct cxd2099_cfg));

While you're still looking at this driver, perhaps you can change the memcpy with a plain struct assignment (if you feel like).
It's really pointless to use a memcpy here.

Something like this:

Review

Quoted 2 lines
(quoted diff) +1 -1
-       memcpy(&ci->cfg, cfg, sizeof(struct cxd2099_cfg));
+       ci->cfg = *cfg;

Correct, and also one more thing like this is

(quoted diff) +1 -1
-           memcpy(&ci->en, &en_templ, sizeof(en_templ));
+          ci->en = en_templ;
Quoted 1 line

Is it ok if i change ci->cfg and ci->en?

Quoted 9 lines

Yes, I believe it is ok.

A few more remarks I would like to add.

1. When sending patches for staging/media, it's not necessary to put staging list/maintainer
(Greg) on Cc. I guess, it doesn't hurt, though.
But it's media list / Mauro who will decide on the patches.

Yeah, for some patches i have done ccing to Greg, but i think you told me not to cc at that time itself so not cc'ed now.

Quoted 10 lines

2. You could also change the order in "struct cxd". Currently it's like this

struct cxd {
        struct dvb_ca_en50221 en;
        struct i2c_adapter *i2c;
        struct cxd2099_cfg cfg;

But it would be better to put it like this

Quoted 9 lines
struct cxd {
        struct i2c_adapter *i2c;
        struct cxd2099_cfg cfg;
        struct dvb_ca_en50221 en;

It's more logical, and ci->i2c and ci->cfg are used more frequently, so it makes sense to put it near the top of the struct.
(You may think I'm being too paranoid: I am).

I am afraid i may not be doing those, if re-ordering may cause some ambiguous problems. sorry...

Quoted 6 lines

3. You don't have hw to test, uh?
In that case, don't forget to always add a "Tested by compilation only" inside the commit message. That way the maintainer (Mauro) are free to _not_ pick
the patch, if he feels it's not safe/clear enough.

Ok . i will definitely put that message in commit. Thanks

Quoted 2 lines

Hope this helps and thanks for your work,
Ezequiel.

Since the changes are different than what this patch does, i will do the changes you proposed in a new patch and will send it out.

Thanks for your time,