Re: [PATCH 5/7] iio: light: tsl2583: check return values from taos_chip_{on, off}

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux