From: Andrew Morton <akpm@linux-foundation.org>
To: Shreshtha Kumar SAHU <shreshthakumar.sahu@stericsson.com>
Cc: <linus.walleij@stericsson.com>,
<richard.purdie@linuxfoundation.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCHv2 1/2] leds: add driver for LM3530 ALS
Date: Thu, 20 Jan 2011 16:04:07 -0800 [thread overview]
Message-ID: <20110120160407.00ffc28e.akpm@linux-foundation.org> (raw)
In-Reply-To: <1295518249-28316-1-git-send-email-shreshthakumar.sahu@stericsson.com>
On Thu, 20 Jan 2011 15:40:49 +0530
Shreshtha Kumar SAHU <shreshthakumar.sahu@stericsson.com> wrote:
> From: Shreshtha Kumar Sahu <shreshthakumar.sahu@stericsson.com>
>
> simple backlight driver for National Semiconductor LM3530.
> Presently only manual mode is supported, PWM and ALS support
> to be added.
>
>
> ...
>
> +static int lm3530_get_mode_from_str(const char *str, int count)
> +{
> + int i;
> +
> + if (str[0] == '\n')
> + return -1;
Why is this here? I think the function would work OK if it was removed?
> + for (i = 0; i < LM3530_BL_MODE_MAX; i++)
Could use ARRAY_SIZE(mode_map) here and do away with
LM3530_BL_MODE_MAX.
> + if (!strncmp(mode_map[i].mode, str, count))
Why strncmp? The code will treat input of the form "alsfoo" as "als",
which is sloppy.
> + return mode_map[i].mode_val;
> +
> + return -1;
> +}
> +
>
> ...
>
> +static ssize_t lm3530_mode_set(struct device *dev, struct device_attribute
> + *attr, const char *buf, size_t size)
> +{
> + int err;
> + struct i2c_client *client = container_of(
> + dev->parent, struct i2c_client, dev);
> + struct lm3530_data *drvdata = i2c_get_clientdata(client);
> + int mode;
> +
> + mode = lm3530_get_mode_from_str(buf, size-1);
And why the "size-1"? Assuming there's a \n? But userspace should be
able to do write(fd, 3, "als")?
Perhaps all this can be tidied up with
mode = lm3530_get_mode_from_str(strim(buf));
Alternatively, see sysfs_streq() - it was added to address these sorts
of things.
> + if (mode < 0) {
> + dev_err(dev, "Invalid mode\n");
> + return -EINVAL;
> + }
> +
> + if (mode == LM3530_BL_MODE_MANUAL)
> + drvdata->mode = LM3530_BL_MODE_MANUAL;
> + else if (mode == LM3530_BL_MODE_ALS)
> + drvdata->mode = LM3530_BL_MODE_ALS;
> + else if (mode == LM3530_BL_MODE_PWM) {
> + dev_err(dev, "PWM mode not supported\n");
> + return -EINVAL;
> + }
> +
> + err = lm3530_init_registers(drvdata);
> + if (err) {
> + dev_err(dev, "Setting %s Mode failed :%d\n", buf, err);
> + return err;
> + }
> +
> + return sizeof(drvdata->mode);
> +}
> +
>
> ...
>
next prev parent reply other threads:[~2011-01-21 0:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-20 10:10 [PATCHv2 1/2] leds: add driver for LM3530 ALS Shreshtha Kumar SAHU
2011-01-21 0:04 ` Andrew Morton [this message]
2011-01-21 10:35 ` [PATCHv3 " Shreshtha Kumar SAHU
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=20110120160407.00ffc28e.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=linus.walleij@stericsson.com \
--cc=linux-kernel@vger.kernel.org \
--cc=richard.purdie@linuxfoundation.org \
--cc=shreshthakumar.sahu@stericsson.com \
/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