Re: [PATCH v6 1/3] hwmon: Maxim MAX197 support

From: Guenter Roeck
Date: Fri Apr 13 2012 - 20:51:20 EST


On Thu, Apr 12, 2012 at 08:28:53PM -0400, Vivien Didelot wrote:
> Signed-off-by: Vivien Didelot <vivien.didelot@xxxxxxxxxxxxxxxxxxxx>
> ---
[ ... ]

> +
> +/**
> + * 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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/