linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Sampaio <sampaio.ime@gmail.com>
To: Joe Perches <joe@perches.com>
Cc: corbet@lwn.net, rikard.falkeborn@gmail.com,
	gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH v5 2/6] w1: ds2438: fixed if brackets coding style issue
Date: Fri, 16 Apr 2021 19:26:08 -0300	[thread overview]
Message-ID: <20210416222608.z7mfxnxhfx2dgytq@LuizSampaio-PC.localdomain> (raw)
In-Reply-To: <67bacd4825f9c8f1abc225146888c5a50deb924c.camel@perches.com>

On Fri, Apr 09, 2021 at 07:40:57AM -0700, Joe Perches wrote:
> On Fri, 2021-04-09 at 00:09 -0300, Luiz Sampaio wrote:
> > Since there is only one statement inside the if clause, no brackets are
> > required.
> []
> > diff --git a/drivers/w1/slaves/w1_ds2438.c b/drivers/w1/slaves/w1_ds2438.c
> []
> > @@ -287,9 +287,9 @@ static ssize_t iad_read(struct file *filp, struct kobject *kobj,
> >  	if (!buf)
> >  		return -EINVAL;
> >  
> > 
> > -	if (w1_ds2438_get_current(sl, &voltage) == 0) {
> > +	if (w1_ds2438_get_current(sl, &voltage) == 0)
> >  		ret = snprintf(buf, count, "%i\n", voltage);
> > -	} else
> > +	else
> >  		ret = -EIO;
> >  
> > 
> >  	return ret;
> 
> to me this would look better using a style like the below:
> (and it might be better using sysfs_emit and not snprintf too)
> 
> ---
>  drivers/w1/slaves/w1_ds2438.c | 36 ++++++++++++------------------------
>  1 file changed, 12 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/w1/slaves/w1_ds2438.c b/drivers/w1/slaves/w1_ds2438.c
> index 5cfb0ae23e91..9115c5a9bc4f 100644
> --- a/drivers/w1/slaves/w1_ds2438.c
> +++ b/drivers/w1/slaves/w1_ds2438.c
> @@ -279,7 +279,6 @@ static ssize_t iad_read(struct file *filp, struct kobject *kobj,
>  			loff_t off, size_t count)
>  {
>  	struct w1_slave *sl = kobj_to_w1_slave(kobj);
> -	int ret;
>  	int16_t voltage;
>  
>  	if (off != 0)
> @@ -287,12 +286,10 @@ static ssize_t iad_read(struct file *filp, struct kobject *kobj,
>  	if (!buf)
>  		return -EINVAL;
>  
> -	if (w1_ds2438_get_current(sl, &voltage) == 0) {
> -		ret = snprintf(buf, count, "%i\n", voltage);
> -	} else
> -		ret = -EIO;
> +	if (w1_ds2438_get_current(sl, &voltage))
> +		return -EIO;
>  
> -	return ret;
> +	return snprintf(buf, count, "%i\n", voltage);
>  }
>  
>  static ssize_t page0_read(struct file *filp, struct kobject *kobj,
> @@ -330,7 +327,6 @@ static ssize_t temperature_read(struct file *filp, struct kobject *kobj,
>  				loff_t off, size_t count)
>  {
>  	struct w1_slave *sl = kobj_to_w1_slave(kobj);
> -	int ret;
>  	int16_t temp;
>  
>  	if (off != 0)
> @@ -338,12 +334,10 @@ static ssize_t temperature_read(struct file *filp, struct kobject *kobj,
>  	if (!buf)
>  		return -EINVAL;
>  
> -	if (w1_ds2438_get_temperature(sl, &temp) == 0) {
> -		ret = snprintf(buf, count, "%i\n", temp);
> -	} else
> -		ret = -EIO;
> +	if (w1_ds2438_get_temperature(sl, &temp))
> +		return -EIO;
>  
> -	return ret;
> +	return snprintf(buf, count, "%i\n", temp);
>  }
>  
>  static ssize_t vad_read(struct file *filp, struct kobject *kobj,
> @@ -351,7 +345,6 @@ static ssize_t vad_read(struct file *filp, struct kobject *kobj,
>  			loff_t off, size_t count)
>  {
>  	struct w1_slave *sl = kobj_to_w1_slave(kobj);
> -	int ret;
>  	uint16_t voltage;
>  
>  	if (off != 0)
> @@ -359,12 +352,10 @@ static ssize_t vad_read(struct file *filp, struct kobject *kobj,
>  	if (!buf)
>  		return -EINVAL;
>  
> -	if (w1_ds2438_get_voltage(sl, DS2438_ADC_INPUT_VAD, &voltage) == 0) {
> -		ret = snprintf(buf, count, "%u\n", voltage);
> -	} else
> -		ret = -EIO;
> +	if (w1_ds2438_get_voltage(sl, DS2438_ADC_INPUT_VAD, &voltage))
> +		return -EIO;
>  
> -	return ret;
> +	return snprintf(buf, count, "%u\n", voltage);
>  }
>  
>  static ssize_t vdd_read(struct file *filp, struct kobject *kobj,
> @@ -372,7 +363,6 @@ static ssize_t vdd_read(struct file *filp, struct kobject *kobj,
>  			loff_t off, size_t count)
>  {
>  	struct w1_slave *sl = kobj_to_w1_slave(kobj);
> -	int ret;
>  	uint16_t voltage;
>  
>  	if (off != 0)
> @@ -380,12 +370,10 @@ static ssize_t vdd_read(struct file *filp, struct kobject *kobj,
>  	if (!buf)
>  		return -EINVAL;
>  
> -	if (w1_ds2438_get_voltage(sl, DS2438_ADC_INPUT_VDD, &voltage) == 0) {
> -		ret = snprintf(buf, count, "%u\n", voltage);
> -	} else
> -		ret = -EIO;
> +	if (w1_ds2438_get_voltage(sl, DS2438_ADC_INPUT_VDD, &voltage))
> +		return -EIO;
>  
> -	return ret;
> +	return snprintf(buf, count, "%u\n", voltage);
>  }
>  
>  static BIN_ATTR(iad, S_IRUGO | S_IWUSR | S_IWGRP, iad_read, iad_write, 0);
>

Sorry for the late reply! I agree, this would look nicer. I will wait for
the current revision and change this for the next one. 

  reply	other threads:[~2021-04-16 22:25 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210405105009.420924-1-sampaio.ime@gmail.com>
2021-04-09  3:09 ` [PATCH v5 0/9] w1: ds2438: adding support for calibration of current measurements Luiz Sampaio
2021-04-09  3:09   ` [PATCH v5 1/6] w1: ds2438: fixed a coding style issue Luiz Sampaio
2021-04-09  3:09   ` [PATCH v5 2/6] w1: ds2438: fixed if brackets " Luiz Sampaio
2021-04-09  4:39     ` Joe Perches
2021-04-09 14:40     ` Joe Perches
2021-04-16 22:26       ` Luiz Sampaio [this message]
2021-04-09  3:09   ` [PATCH v5 3/6] w1: ds2438: fixed a " Luiz Sampaio
2021-04-09  3:09   ` [PATCH v5 4/6] w1: ds2438: fixing bug that would always get page0 Luiz Sampaio
2021-04-09  3:09   ` [PATCH v5 5/6] w1: ds2438: adding support for reading page1 Luiz Sampaio
2021-04-09  3:09   ` [PATCH v5 6/6] w1: ds2438: support for writing to offset register Luiz Sampaio
2021-04-09  3:15   ` [PATCH v6 0/9] w1: ds2438: adding support for calibration of current measurements Luiz Sampaio
2021-04-09  3:15     ` [PATCH v6 1/6] w1: ds2438: fixed a coding style issue Luiz Sampaio
2021-04-09  3:15     ` [PATCH v6 2/6] w1: ds2438: fixed if brackets " Luiz Sampaio
2021-04-09  3:15     ` [PATCH v6 3/6] w1: ds2438: fixed a " Luiz Sampaio
2021-04-09  9:44       ` kernel test robot
2021-04-09 10:43       ` kernel test robot
2021-04-10  8:38       ` Greg KH
2021-04-09  3:15     ` [PATCH v6 4/6] w1: ds2438: fixing bug that would always get page0 Luiz Sampaio
2021-04-09  3:15     ` [PATCH v6 5/6] w1: ds2438: adding support for reading page1 Luiz Sampaio
2021-04-09  3:15     ` [PATCH v6 6/6] w1: ds2438: support for writing to offset register Luiz Sampaio
2021-04-16 22:17     ` [PATCH v7 0/6] w1: ds2438: adding support for calibration of current measurements Luiz Sampaio
2021-04-16 22:17       ` [PATCH v7 1/6] w1: ds2438: fixed a coding style issue Luiz Sampaio
2021-04-16 22:17       ` [PATCH v7 2/6] w1: ds2438: fixed if brackets " Luiz Sampaio
2021-04-16 22:17       ` [PATCH v7 3/6] w1: ds2438: changed sysfs macro for rw file Luiz Sampaio
2021-04-16 22:17       ` [PATCH v7 4/6] w1: ds2438: fixing bug that would always get page0 Luiz Sampaio
2021-04-16 22:17       ` [PATCH v7 5/6] w1: ds2438: adding support for reading page1 Luiz Sampaio
2021-04-16 22:17       ` [PATCH v7 6/6] w1: ds2438: support for writing to offset register Luiz Sampaio
2021-04-17  5:25         ` kernel test robot
2021-05-14 11:47       ` [PATCH v7 0/6] w1: ds2438: adding support for calibration of current measurements Greg KH
2021-05-19 22:30     ` [PATCH v8 " Luiz Sampaio
2021-05-19 22:30       ` [PATCH v8 1/6] w1: ds2438: fixed a coding style issue Luiz Sampaio
2021-05-19 22:30       ` [PATCH v8 2/6] w1: ds2438: fixed if brackets " Luiz Sampaio
2021-05-19 22:30       ` [PATCH v8 3/6] w1: ds2438: changed sysfs macro for rw file Luiz Sampaio
2021-05-19 22:30       ` [PATCH v8 4/6] w1: ds2438: fixing bug that would always get page0 Luiz Sampaio
2021-05-19 22:30       ` [PATCH v8 5/6] w1: ds2438: adding support for reading page1 Luiz Sampaio
2021-05-19 22:30       ` [PATCH v8 6/6] w1: ds2438: support for writing to offset register Luiz Sampaio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210416222608.z7mfxnxhfx2dgytq@LuizSampaio-PC.localdomain \
    --to=sampaio.ime@gmail.com \
    --cc=corbet@lwn.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=joe@perches.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rikard.falkeborn@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).