From: Guenter Roeck <guenter.roeck@ericsson.com>
To: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Cc: "x86@kernel.org" <x86@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"lm-sensors@lm-sensors.org" <lm-sensors@lm-sensors.org>,
Jean Delvare <khali@linux-fr.org>,
Grant Likely <grant.likely@secretlab.ca>,
Linus Walleij <linus.walleij@stericsson.com>
Subject: Re: [lm-sensors] [PATCH v6 1/3] hwmon: Maxim MAX197 support
Date: Sat, 14 Apr 2012 00:46:02 +0000 [thread overview]
Message-ID: <20120414004602.GA5609@ericsson.com> (raw)
In-Reply-To: <1334276935-11258-2-git-send-email-vivien.didelot@savoirfairelinux.com>
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
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
WARNING: multiple messages have this Message-ID (diff)
From: Guenter Roeck <guenter.roeck@ericsson.com>
To: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Cc: "x86@kernel.org" <x86@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"lm-sensors@lm-sensors.org" <lm-sensors@lm-sensors.org>,
Jean Delvare <khali@linux-fr.org>,
Grant Likely <grant.likely@secretlab.ca>,
Linus Walleij <linus.walleij@stericsson.com>
Subject: Re: [PATCH v6 1/3] hwmon: Maxim MAX197 support
Date: Fri, 13 Apr 2012 17:46:02 -0700 [thread overview]
Message-ID: <20120414004602.GA5609@ericsson.com> (raw)
In-Reply-To: <1334276935-11258-2-git-send-email-vivien.didelot@savoirfairelinux.com>
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
next prev parent reply other threads:[~2012-04-14 0:46 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-13 0:28 [lm-sensors] [PATCH v6 0/3] TS-5500 platform support Vivien Didelot
2012-04-13 0:28 ` Vivien Didelot
2012-04-13 0:28 ` [lm-sensors] [PATCH v6 1/3] hwmon: Maxim MAX197 support Vivien Didelot
2012-04-13 0:28 ` Vivien Didelot
2012-04-14 0:46 ` Guenter Roeck [this message]
2012-04-14 0:46 ` Guenter Roeck
2012-04-13 0:28 ` [lm-sensors] [PATCH v6 2/3] x86/platform: TS-5500 basic platform support Vivien Didelot
2012-04-13 0:28 ` Vivien Didelot
2012-04-13 10:37 ` [lm-sensors] " Thomas Gleixner
2012-04-13 10:37 ` Thomas Gleixner
2012-04-13 20:46 ` [lm-sensors] " Vivien Didelot
2012-04-13 20:46 ` Vivien Didelot
2012-04-13 0:28 ` [lm-sensors] [PATCH v6 3/3] gpio: TS-5500 GPIO support Vivien Didelot
2012-04-13 0:28 ` Vivien Didelot
2012-04-13 19:04 ` [lm-sensors] " Mark Brown
2012-04-13 19:04 ` Mark Brown
2012-05-17 21:06 ` [lm-sensors] " Grant Likely
2012-05-17 21:06 ` Grant Likely
2012-05-17 21:14 ` [lm-sensors] " Joe Perches
2012-05-17 21:14 ` Joe Perches
2012-05-17 21:40 ` [lm-sensors] " Vivien Didelot
2012-05-17 21:40 ` Vivien Didelot
2012-05-17 22:59 ` [lm-sensors] " Grant Likely
2012-05-17 22:59 ` Grant Likely
2012-05-18 14:37 ` [lm-sensors] " Vivien Didelot
2012-05-18 14:37 ` Vivien Didelot
2012-05-18 19:59 ` [lm-sensors] " Grant Likely
2012-05-18 19:59 ` Grant Likely
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=20120414004602.GA5609@ericsson.com \
--to=guenter.roeck@ericsson.com \
--cc=grant.likely@secretlab.ca \
--cc=hpa@zytor.com \
--cc=khali@linux-fr.org \
--cc=linus.walleij@stericsson.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lm-sensors@lm-sensors.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=vivien.didelot@savoirfairelinux.com \
--cc=x86@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.