Re: [PATCH v3] leds: add LM3533 LED driver

From: Johan Hovold
Date: Mon May 14 2012 - 06:26:03 EST


On Fri, May 11, 2012 at 03:24:36PM -0700, Andrew Morton wrote:
> On Fri, 11 May 2012 11:54:11 +0200
> Johan Hovold <jhovold@xxxxxxxxx> wrote:
> > On Thu, May 10, 2012 at 11:48:17AM -0700, Andrew Morton wrote:
> > > On Thu, 10 May 2012 20:27:05 +0200
> > > Johan Hovold <jhovold@xxxxxxxxx> wrote:
> > >
> > > > Add sub-driver for the LEDs on National Semiconductor / TI LM3533
> > > > lighting power chips.
> > > >
> > > > The chip provides 256 brightness levels, hardware accelerated blinking
> > > > as well as ambient-light-sensor and pwm input control.

[...]

> > > > +static ssize_t store_als(struct device *dev,
> > > > + struct device_attribute *attr,
> > > > + const char *buf, size_t len)
> > > > +{
> > > > + struct led_classdev *led_cdev = dev_get_drvdata(dev);
> > > > + struct lm3533_led *led = to_lm3533_led(led_cdev);
> > > > + u8 als;
> > > > + u8 reg;
> > > > + u8 mask;
> > > > + int ret;
> > > > +
> > > > + if (kstrtou8(buf, 0, &als))
> > > > + return -EINVAL;
> > > > +
> > > > + if (als != 0 && (als < LM3533_ALS_LV_MIN || als > LM3533_ALS_LV_MAX))
> > > > + return -EINVAL;
> > >
> > > The `als != 0' test doesn't do anything, and looks odd. Is there some
> > > magical reason why als==0 would be illegal even if LM3533_ALS_LV_MIN
> > > was negative? If so, it should be documented.
> >
> > The non-zero-test is not redundant as 0 is the only valid input outside
> > of [LV_MIN,LV_MAX] (in fact, the only three valid values are 0,2 and 3).
>
> ah, OK. One day I'll get the hang of this C thingy.
>
> > Would you prefer
> >
> > if ((als < LM3533_ALS_LV_MIN && als != 0) || als > LM3533_ALS_LV_MAX)
> > return -EINVAL;
> >
> > or nested conditionals? Or should I simply add a comment?
>
> A comment would be nice. That 0 is also permitted is a surprise.

Actually, there is a comment already documenting the valid values and
it's placed above the show function immediately above the store one:

/*
* ALS-control setting:
*
* 0 - ALS disabled
* 2 - ALS-mapper 2
* 3 - ALS-mapper 3
*/
static ssize_t show_als(struct device *dev,
...
static ssize_t store_als(struct device *dev,


Thanks,
Johan
--
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/