linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Brian Masney <masneyb@onstation.org>
Cc: jic23@kernel.org, devel@driverdev.osuosl.org, lars@metafoo.de,
	linux-iio@vger.kernel.org, gregkh@linuxfoundation.org,
	linux-kernel@vger.kernel.org, pmeerw@pmeerw.net, knaack.h@gmx.de
Subject: Re: [PATCH 5/7] iio: light: tsl2583: check return values from taos_chip_{on, off}
Date: Wed, 19 Oct 2016 14:22:49 +0300	[thread overview]
Message-ID: <20161019112249.GH4469@mwanda> (raw)
In-Reply-To: <1476873130-24926-5-git-send-email-masneyb@onstation.org>

On Wed, Oct 19, 2016 at 06:32:08AM -0400, Brian Masney wrote:
> @@ -775,14 +778,20 @@ static ssize_t illuminance0_lux_table_store(struct device *dev,
>  		goto luxable_store_done;
>  	}
>  
> -	if (chip->taos_chip_status == TSL258X_CHIP_WORKING)
> -		taos_chip_off(indio_dev);
> +	if (chip->taos_chip_status == TSL258X_CHIP_WORKING) {
> +		ret = taos_chip_off(indio_dev);
> +		if (ret < 0)
> +			return ret;
> +	}
>  
>  	/* Zero out the table */
>  	memset(taos_device_lux, 0, sizeof(taos_device_lux));
>  	memcpy(taos_device_lux, &value[1], (value[0] * 4));
>  
> -	taos_chip_on(indio_dev);
> +	ret = taos_chip_on(indio_dev);
> +	if (ret < 0)
> +		return ret;
> +
>  	ret = len;
>  
>  luxable_store_done:


See, here you are adding direct returns in the middle of a single return
function, and you promised yourself that you would never do that and it
would mean that you never ever forgot to add error handling.  But we're
not even outside of the patchset yet and your complicated future
proofing has already failed.

You know you just want direct returns because that is the simplest way
to program.  "goto luxable_store_done;"  What does that even mean?  But
"return -EINVAL;" is simple.  It does one thing and it does it well.

Go with your heart.  My research says that the complicated single return
functions are going to be buggier in the long run anyway so your heart
is leading you on the right path.

regards,
dan carpenter


  reply	other threads:[~2016-10-19 14:41 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-19 10:32 [PATCH 1/7] iio: light: tsl2583: return proper error code Brian Masney
2016-10-19 10:32 ` [PATCH 2/7] iio: light: tsl2583: change functions to only have a single exit point Brian Masney
2016-10-19 11:08   ` Dan Carpenter
2016-10-19 12:38     ` Brian Masney
2016-10-19 12:51       ` Dan Carpenter
2016-10-19 10:32 ` [PATCH 3/7] iio: light: tsl2583: use DEVICE_ATTR_{RO, RW, WO} macros Brian Masney
2016-10-19 10:47   ` Peter Meerwald-Stadler
2016-10-19 13:04     ` Brian Masney
2016-10-19 11:26   ` Dan Carpenter
2016-10-19 13:08     ` Brian Masney
2016-10-19 13:11       ` Dan Carpenter
2016-10-22 17:25         ` Jonathan Cameron
2016-10-19 16:30   ` Jonathan Cameron
2016-10-19 10:32 ` [PATCH 4/7] iio: light: tsl2583: return proper error code in sysfs store functions Brian Masney
2016-10-19 10:32 ` [PATCH 5/7] iio: light: tsl2583: check return values from taos_chip_{on,off} Brian Masney
2016-10-19 11:22   ` Dan Carpenter [this message]
2016-10-19 12:48     ` [PATCH 5/7] iio: light: tsl2583: check return values from taos_chip_{on, off} Brian Masney
2016-10-19 12:54       ` Dan Carpenter
2016-10-19 12:57         ` Dan Carpenter
2016-10-19 10:32 ` [PATCH 6/7] iio: light: tsl2583: add locking to sysfs *_store() functions Brian Masney
2016-10-19 11:33   ` Dan Carpenter
2016-10-19 11:37     ` Dan Carpenter
2016-10-22 17:29       ` Jonathan Cameron
2016-10-24  9:35         ` Dan Carpenter
2016-10-19 10:32 ` [PATCH 7/7] iio: light: tsl2583: fix concurrency issue in taos_get_lux() Brian Masney
2016-10-22 17:32   ` Jonathan Cameron
2016-10-22 17:18 ` [PATCH 1/7] iio: light: tsl2583: return proper error code Jonathan Cameron

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=20161019112249.GH4469@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masneyb@onstation.org \
    --cc=pmeerw@pmeerw.net \
    /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).