2012-06-19 19:05:56

by devendra.aaru

[permalink] [raw]
Subject: [PATCH V2 1/3] staging/rtl8192u: fix coding style problems

fixed some of the coding style problems reported by checkpatch

Signed-off-by: Devendra Naga <[email protected]>
---
drivers/staging/rtl8192u/r8180_93cx6.c | 36 +++++++++++++++++---------------
1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8180_93cx6.c b/drivers/staging/rtl8192u/r8180_93cx6.c
index 3c515b7..19f5270 100644
--- a/drivers/staging/rtl8192u/r8180_93cx6.c
+++ b/drivers/staging/rtl8192u/r8180_93cx6.c
@@ -22,13 +22,16 @@

void eprom_cs(struct net_device *dev, short bit)
{
- if(bit)
+ if (bit) {
+ /* enable EPROM */
write_nic_byte_E(dev, EPROM_CMD,
- (1<<EPROM_CS_SHIFT) | \
- read_nic_byte_E(dev, EPROM_CMD)); //enable EPROM
- else
- write_nic_byte_E(dev, EPROM_CMD, read_nic_byte_E(dev, EPROM_CMD)\
- &~(1<<EPROM_CS_SHIFT)); //disable EPROM
+ (1<<EPROM_CS_SHIFT) |
+ read_nic_byte_E(dev, EPROM_CMD));
+ } else {
+ /* disable EPROM */
+ write_nic_byte_E(dev, EPROM_CMD, read_nic_byte_E(dev, EPROM_CMD)
+ & ~(1<<EPROM_CS_SHIFT));
+ }

force_pci_posting(dev);
udelay(EPROM_DELAY);
@@ -38,24 +41,24 @@ void eprom_cs(struct net_device *dev, short bit)
void eprom_ck_cycle(struct net_device *dev)
{
write_nic_byte_E(dev, EPROM_CMD,
- (1<<EPROM_CK_SHIFT) | read_nic_byte_E(dev,EPROM_CMD));
+ (1<<EPROM_CK_SHIFT) | read_nic_byte_E(dev, EPROM_CMD));
force_pci_posting(dev);
udelay(EPROM_DELAY);
write_nic_byte_E(dev, EPROM_CMD,
- read_nic_byte_E(dev, EPROM_CMD) &~ (1<<EPROM_CK_SHIFT));
+ read_nic_byte_E(dev, EPROM_CMD) & ~(1<<EPROM_CK_SHIFT));
force_pci_posting(dev);
udelay(EPROM_DELAY);
}


-void eprom_w(struct net_device *dev,short bit)
+void eprom_w(struct net_device *dev, short bit)
{
- if(bit)
- write_nic_byte_E(dev, EPROM_CMD, (1<<EPROM_W_SHIFT) | \
- read_nic_byte_E(dev,EPROM_CMD));
+ if (bit)
+ write_nic_byte_E(dev, EPROM_CMD, (1<<EPROM_W_SHIFT) |
+ read_nic_byte_E(dev, EPROM_CMD));
else
- write_nic_byte_E(dev, EPROM_CMD, read_nic_byte_E(dev,EPROM_CMD)\
- &~(1<<EPROM_W_SHIFT));
+ write_nic_byte_E(dev, EPROM_CMD, read_nic_byte_E(dev, EPROM_CMD)
+ & ~(1<<EPROM_W_SHIFT));

force_pci_posting(dev);
udelay(EPROM_DELAY);
@@ -66,11 +69,10 @@ short eprom_r(struct net_device *dev)
{
short bit;

- bit=(read_nic_byte_E(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT) );
+ bit = (read_nic_byte_E(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT));
udelay(EPROM_DELAY);

- if(bit) return 1;
- return 0;
+ return !!bit;
}


--
1.7.9.5


2012-06-20 23:08:45

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH V2 1/3] staging/rtl8192u: fix coding style problems

On Wed, Jun 20, 2012 at 12:35:42AM +0530, Devendra Naga wrote:
> fixed some of the coding style problems reported by checkpatch
>
> Signed-off-by: Devendra Naga <[email protected]>
> ---
> drivers/staging/rtl8192u/r8180_93cx6.c | 36 +++++++++++++++++---------------
> 1 file changed, 19 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/staging/rtl8192u/r8180_93cx6.c b/drivers/staging/rtl8192u/r8180_93cx6.c
> index 3c515b7..19f5270 100644
> --- a/drivers/staging/rtl8192u/r8180_93cx6.c
> +++ b/drivers/staging/rtl8192u/r8180_93cx6.c
> @@ -22,13 +22,16 @@
>
> void eprom_cs(struct net_device *dev, short bit)
> {
> - if(bit)
> + if (bit) {
> + /* enable EPROM */
> write_nic_byte_E(dev, EPROM_CMD,
> - (1<<EPROM_CS_SHIFT) | \
> - read_nic_byte_E(dev, EPROM_CMD)); //enable EPROM
> - else
> - write_nic_byte_E(dev, EPROM_CMD, read_nic_byte_E(dev, EPROM_CMD)\
> - &~(1<<EPROM_CS_SHIFT)); //disable EPROM
> + (1<<EPROM_CS_SHIFT) |
> + read_nic_byte_E(dev, EPROM_CMD));
> + } else {
> + /* disable EPROM */
> + write_nic_byte_E(dev, EPROM_CMD, read_nic_byte_E(dev, EPROM_CMD)
> + & ~(1<<EPROM_CS_SHIFT));
> + }
>
> force_pci_posting(dev);
> udelay(EPROM_DELAY);
> @@ -38,24 +41,24 @@ void eprom_cs(struct net_device *dev, short bit)
> void eprom_ck_cycle(struct net_device *dev)
> {
> write_nic_byte_E(dev, EPROM_CMD,
> - (1<<EPROM_CK_SHIFT) | read_nic_byte_E(dev,EPROM_CMD));
> + (1<<EPROM_CK_SHIFT) | read_nic_byte_E(dev, EPROM_CMD));
> force_pci_posting(dev);
> udelay(EPROM_DELAY);
> write_nic_byte_E(dev, EPROM_CMD,
> - read_nic_byte_E(dev, EPROM_CMD) &~ (1<<EPROM_CK_SHIFT));
> + read_nic_byte_E(dev, EPROM_CMD) & ~(1<<EPROM_CK_SHIFT));
> force_pci_posting(dev);
> udelay(EPROM_DELAY);
> }
>
>
> -void eprom_w(struct net_device *dev,short bit)
> +void eprom_w(struct net_device *dev, short bit)
> {
> - if(bit)
> - write_nic_byte_E(dev, EPROM_CMD, (1<<EPROM_W_SHIFT) | \
> - read_nic_byte_E(dev,EPROM_CMD));
> + if (bit)
> + write_nic_byte_E(dev, EPROM_CMD, (1<<EPROM_W_SHIFT) |
> + read_nic_byte_E(dev, EPROM_CMD));
> else
> - write_nic_byte_E(dev, EPROM_CMD, read_nic_byte_E(dev,EPROM_CMD)\
> - &~(1<<EPROM_W_SHIFT));
> + write_nic_byte_E(dev, EPROM_CMD, read_nic_byte_E(dev, EPROM_CMD)
> + & ~(1<<EPROM_W_SHIFT));
>
> force_pci_posting(dev);
> udelay(EPROM_DELAY);
> @@ -66,11 +69,10 @@ short eprom_r(struct net_device *dev)
> {
> short bit;
>
> - bit=(read_nic_byte_E(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT) );
> + bit = (read_nic_byte_E(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT));
> udelay(EPROM_DELAY);
>
> - if(bit) return 1;
> - return 0;
> + return !!bit;

Oh come on, really? !! is more "clear" here?

No, please be painfully obvious, that's the only way to write kernel
code. Not like this.

greg k-h

2012-06-20 23:18:39

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH V2 1/3] staging/rtl8192u: fix coding style problems

On Wed, 2012-06-20 at 16:08 -0700, Greg Kroah-Hartman wrote:
> On Wed, Jun 20, 2012 at 12:35:42AM +0530, Devendra Naga wrote:
> > fixed some of the coding style problems reported by checkpatch
[]
> > @@ -66,11 +69,10 @@ short eprom_r(struct net_device *dev)
> > {
> > short bit;
> >
> > - bit=(read_nic_byte_E(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT) );
> > + bit = (read_nic_byte_E(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT));
> > udelay(EPROM_DELAY);
> >
> > - if(bit) return 1;
> > - return 0;
> > + return !!bit;
>
> Oh come on, really? !! is more "clear" here?

Depends on the reader. !! is pretty common.

> No, please be painfully obvious, that's the only way to write kernel
> code. Not like this.

I'd just make the return a bool instead.

Also, there are unnecessary parens that could
be removed to make the code clearer.

(1<<EPROM_R_SHIFT), (1<<EPROM_W_SHIFT) and
(1<<EPROM_CK_SHIFT) could be new #defines too.

2012-06-23 18:29:58

by devendra.aaru

[permalink] [raw]
Subject: Re: [PATCH V2 1/3] staging/rtl8192u: fix coding style problems

On Thu, Jun 21, 2012 at 4:38 AM, Greg Kroah-Hartman
<[email protected]> wrote:
> On Wed, Jun 20, 2012 at 12:35:42AM +0530, Devendra Naga wrote:
>> - ? ? bit=(read_nic_byte_E(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT) );
>> + ? ? bit = (read_nic_byte_E(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT));
>> ? ? ? udelay(EPROM_DELAY);
>>
>> - ? ? if(bit) return 1;
>> - ? ? return 0;
>> + ? ? return !!bit;
>
> Oh come on, really? ?!! is more "clear" here?
>
It looks ok to me,
> No, please be painfully obvious, that's the only way to write kernel
> code. ?Not like this.
>
Ok, so no !!'s ? and just that if (bit) thingy?

> greg k-h

2012-06-23 18:34:14

by devendra.aaru

[permalink] [raw]
Subject: Re: [PATCH V2 1/3] staging/rtl8192u: fix coding style problems

Hi Joe,

On Thu, Jun 21, 2012 at 4:48 AM, Joe Perches <[email protected]> wrote:
> On Wed, 2012-06-20 at 16:08 -0700, Greg Kroah-Hartman wrote:
>> On Wed, Jun 20, 2012 at 12:35:42AM +0530, Devendra Naga wrote:
>> > fixed some of the coding style problems reported by checkpatch
> []
>> > @@ -66,11 +69,10 @@ short eprom_r(struct net_device *dev)
>> > ?{
>> > ? ? short bit;
>> >
>> > - ? bit=(read_nic_byte_E(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT) );
>> > + ? bit = (read_nic_byte_E(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT));
>> > ? ? udelay(EPROM_DELAY);
>> >
>> > - ? if(bit) return 1;
>> > - ? return 0;
>> > + ? return !!bit;
>>
>> Oh come on, really? ?!! is more "clear" here?
>
> Depends on the reader. ?!! is pretty common.
>
>> No, please be painfully obvious, that's the only way to write kernel
>> code. ?Not like this.
>
> I'd just make the return a bool instead.
>
taking another variable and assign it like bool ret = !!bit, and
returning ret?, i think this doesn't look better.
> Also, there are unnecessary parens that could
> be removed to make the code clearer.
>
> (1<<EPROM_R_SHIFT), (1<<EPROM_W_SHIFT) and
> (1<<EPROM_CK_SHIFT) could be new #defines too.
>
>
Will do.

thanks joe.


Devendra.

2012-06-23 19:11:09

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH V2 1/3] staging/rtl8192u: fix coding style problems

On Sun, Jun 24, 2012 at 12:04:12AM +0530, devendra.aaru wrote:
> Hi Joe,
>
> On Thu, Jun 21, 2012 at 4:48 AM, Joe Perches <[email protected]> wrote:
> > On Wed, 2012-06-20 at 16:08 -0700, Greg Kroah-Hartman wrote:
> >> On Wed, Jun 20, 2012 at 12:35:42AM +0530, Devendra Naga wrote:
> >> > fixed some of the coding style problems reported by checkpatch
> > []
> >> > @@ -66,11 +69,10 @@ short eprom_r(struct net_device *dev)
> >> > ?{
> >> > ? ? short bit;
> >> >
> >> > - ? bit=(read_nic_byte_E(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT) );
> >> > + ? bit = (read_nic_byte_E(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT));
> >> > ? ? udelay(EPROM_DELAY);
> >> >
> >> > - ? if(bit) return 1;
> >> > - ? return 0;
> >> > + ? return !!bit;
> >>
> >> Oh come on, really? ?!! is more "clear" here?
> >
> > Depends on the reader. ?!! is pretty common.
> >
> >> No, please be painfully obvious, that's the only way to write kernel
> >> code. ?Not like this.
> >
> > I'd just make the return a bool instead.
> >
> taking another variable and assign it like bool ret = !!bit, and
> returning ret?, i think this doesn't look better.

*eye roll*

if (bit)
return 1;
return 0;

regards,
dan carpenter

2012-06-23 20:51:57

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH V2 1/3] staging/rtl8192u: fix coding style problems

On Sun, 2012-06-24 at 00:04 +0530, devendra.aaru wrote:
> Hi Joe,

Hi Devendra.

> On Thu, Jun 21, 2012 at 4:48 AM, Joe Perches <[email protected]> wrote:
> > I'd just make the return a bool instead.

> taking another variable and assign it like bool ret = !!bit, and
> returning ret?, i think this doesn't look better.

No. just
return val;
or
return (bool)val;

if using the implicit conversion bothers you.