lkml.org 
[lkml]   [2012]   [Apr]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v6 1/3] hwmon: Maxim MAX197 support
On Thu, Apr 12, 2012 at 08:28:53PM -0400, Vivien Didelot wrote:
> Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
> ---
[ ... ]

> +
> +/**
> + * max197_show_input() - Show channel input
> + *
> + * Function called on read access on in{0,1,2,3,4,5,6,7}_input
> + */
> +static ssize_t max197_show_input(struct device *dev,
> + struct device_attribute *devattr,
> + char *buf)
> +{
> + struct max197_chip *chip = dev_get_drvdata(dev);
> + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> + int channel = attr->index;
> + u16 raw;
> + s32 scaled;
> + int ret;
> +
> + if (mutex_lock_interruptible(&chip->lock))
> + return -ERESTARTSYS;
> +
> + ret = chip->pdata->convert(chip->ctrl_bytes[channel], &raw);
> + if (ret) {
> + dev_err(dev, "conversion failed\n");
> + goto unlock;
> + }

Hi Vivien,

thinking about this, you can simplify the API to

ret = chip->pdata->convert(chip->ctrl_bytes[channel]);
if (ret < 0) {
dev_err(dev, "conversion failed\n");
goto unlock;
}
scaled = ret;

This overloads the return value with both error code (< 0) and return value (unsigned, >= 0).
This would make the code a bit simpler and smaller.

Thanks,
Guenter


\
 
 \ /
  Last update: 2012-04-14 02:53    [W:0.100 / U:0.200 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site