staging: rtl8712: Replace kmalloc by kzalloc.
PATCH 3/3 staging: rtl8712: Replace kmalloc by kzalloc.
Mainly the issue is that bool variables can have invalid values. So as memory allocated with kmalloc() is essentially random, any struct that contains bools, is allocated with kmalloc() and doesn't have the bools explicitly set might have invalid values.
This is easily fixed by allocating it with kzalloc().
--- drivers/staging/rtl8712/rtl871x_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8712/rtl871x_io.c +1 -1
@@ -60,7 +60,7 @@ static uint _init_intf_hdl(struct _adapter *padapter, set_intf_funs = &(r8712_usb_set_intf_funs); set_intf_ops = &r8712_usb_set_intf_ops; init_intf_priv = &r8712_usb_init_intf_priv; - pintf_priv = pintf_hdl->pintfpriv =kmalloc (sizeof (struct intf_priv ), + pintf_priv = pintf_hdl->pintfpriv =kzalloc (sizeof (struct intf_priv ),GFP_ATOMIC );if (pintf_priv ==NULL ) goto _init_intf_hdl_fail;
Signature · 1 line
1.9.1
Greg KH
maintainerQuoted 16 lines · Rakhi Sharma
Mainly the issue is that bool variables can have invalid values. So as memory allocated with
kmalloc()is essentially random, any struct that contains bools, is allocated withkmalloc()and doesn't have the bools explicitly set might have invalid values.
This is easily fixed by allocating it withkzalloc().Signed-off-by Rakhi Sharma <[email protected]>--- drivers/staging/rtl8712/rtl871x_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/rtl8712/rtl871x_io.c +0
-0
drivers/staging/rtl8712/rtl871x_io.c static uint _init_intf_hdl(struct _adapter *padapter, · line 64
Quoted 6 lines
drivers/staging/rtl8712/rtl871x_io.c +1
-1@@ -60,7 +60,7 @@ static uint _init_intf_hdl(struct _adapter *padapter, set_intf_funs = &(r8712_usb_set_intf_funs); set_intf_ops = &r8712_usb_set_intf_ops; init_intf_priv = &r8712_usb_init_intf_priv; - pintf_priv = pintf_hdl->pintfpriv =kmalloc (sizeof (struct intf_priv ), + pintf_priv = pintf_hdl->pintfpriv =kzalloc (sizeof (struct intf_priv ),GFP_ATOMIC );
Why is this needed? Don't do a zero-fill unless the code is expecting/wanting it. Are you sure that the fields don't already get set properly? Is this a waste of time?
We need a lot more information, you can't just blindly convert these calls, especially on "fast paths", like I think this might be.
sorry,
greg k-h
Quoted 23 lines · Greg KH
Quoted 6 lines · Rakhi Sharma
Mainly the issue is that bool variables can have invalid values. So as memory allocated with
kmalloc()is essentially random, any struct that contains bools, is allocated withkmalloc()and doesn't have the bools explicitly set might have invalid values.
This is easily fixed by allocating it withkzalloc().Review
Quoted 6 lines
Signed-off-by Rakhi Sharma <[email protected]>--- drivers/staging/rtl8712/rtl871x_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/staging/rtl8712/rtl871x_io.cdrivers/staging/rtl8712/rtl871x_io.c static uint _init_intf_hdl(struct _adapter *padapter, · line 63
Quoted 8 lines
index fbbc635..2891b82 100644
drivers/staging/rtl8712/rtl871x_io.c +0
-1@@ -60,7 +60,7 @@ static uint _init_intf_hdl(struct _adapter *padapter, set_intf_funs = &(r8712_usb_set_intf_funs); set_intf_ops = &r8712_usb_set_intf_ops; init_intf_priv = &r8712_usb_init_intf_priv; - pintf_priv = pintf_hdl->pintfpriv = kmalloc(sizeof(struct
intf_priv),
Quoted 8 lines
drivers/staging/rtl8712/rtl871x_io.c static uint _init_intf_hdl(struct _adapter *padapter, · line 63
Quoted 1 line
drivers/staging/rtl8712/rtl871x_io.c +1
-0+ pintf_priv = pintf_hdl->pintfpriv = kzalloc(sizeof(struct
intf_priv),drivers/staging/rtl8712/rtl871x_io.c static uint _init_intf_hdl(struct _adapter *padapter, · line 64
Quoted 1 line
drivers/staging/rtl8712/rtl871x_io.c +0
-0GFP_ATOMIC);Hi Greg,
Why is this needed? Don't do a zero-fill unless the code is expecting/wanting it.
Sure I will take care of it in future.
Quoted 4 lines
Are you sure that the fields don't already get
set properly? Is this a waste of time?I was going through this file and found the kmalloc function I read the
code and thought
it need change, as it is always better to use kzalloc.May be it will usefull in future or
may be not. In my previous contribution (before outreachy round), one of maintainer
advise me to do this in case if I found it ok. and I really don't think this is waste of time.
Please let me know if I am doing wrong :)
Quoted 4 lines
We need a lot more information, you can't just blindly convert these calls, especially on "fast paths", like I think this might be.
Please let me know what information you need, I will try to deliver that
:)
sorry,
Quoted 3 lines
greg k-h
Greg KH
maintainerQuoted 39 lines · RAKHI SHARMA
On Fri, Feb 12, 2016 at 8:40 AM, Greg KH <[email protected]> wrote:
On Fri, Feb 12, 2016 at 08:09:46AM +0530, Rakhi Sharma wrote: > Mainly the issue is that bool variables can have invalid values. > So as memory allocated with kmalloc() is essentially random, any struct > that contains bools, is allocated with kmalloc() and doesn't have the > bools explicitly set might have invalid values. > This is easily fixed by allocating it with kzalloc(). > > Signed-off-by: Rakhi Sharma <[email protected]> > --- >� drivers/staging/rtl8712/rtl871x_io.c | 2 +- >� 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/staging/rtl8712/rtl871x_io.c b/drivers/staging/ rtl8712/rtl871x_io.c > index fbbc635..2891b82 100644 > --- a/drivers/staging/rtl8712/rtl871x_io.c > +++ b/drivers/staging/rtl8712/rtl871x_io.c > @@ -60,7 +60,7 @@ static uint _init_intf_hdl(struct _adapter *padapter, >� � � �set_intf_funs = &(r8712_usb_set_intf_funs); >� � � �set_intf_ops = &r8712_usb_set_intf_ops; >� � � �init_intf_priv = &r8712_usb_init_intf_priv; > -� � �pintf_priv = pintf_hdl->pintfpriv = kmalloc(sizeof(struct intf_priv), > +� � �pintf_priv = pintf_hdl->pintfpriv = kzalloc(sizeof(struct intf_priv), >� � � � � � � � � � � � � � � � � � � � � � � � � �GFP_ATOMIC);Hi Greg,
Why is this needed?� Don't do a zero-fill unless the code is expecting/wanting it.
Sure I will take care of it in future.
�
Quoted 7 lines
� Are you sure that the fields don't already get set properly?� Is this a waste of time?
I was going through this file and found the kmalloc function I read the code and thought
it need change, as it is always better to use kzalloc.
It is not always better to use kzalloc, otherwise we would just get rid of kmalloc and replace it with kzalloc, or change kmalloc to zero out all memory.
Quoted 1 line
May be it will usefull in future or may be not.
It has to be useful now to matter.
Quoted 7 lines
In my previous
contribution (before outreachy round), one of
maintainer
advise me to do this in case if I found it ok. and I really don't think this is waste of time.
Please let me know if I am doing wrong :)
Quoted 7 lines
�
We need a lot more information, you can't just blindly convert these calls, especially on "fast paths", like I think this might be.
Please let me know what information you need, I will try to deliver that :)
What benifit does this code change cause? Why is it needed? What fields are not being set to zero that somehow could leak information before your change that your change fixes? Why is zeroing out the memory better/faster/nicer/etc. now?
In short you have to prove this is a fix, as it is, I can't see that here just yet.
hope this helps,
greg k-h