Message ID | 20171019200632.25820-14-masneyb@onstation.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Thu, 19 Oct 2017 16:06:32 -0400 Brian Masney <masneyb@onstation.org> wrote: > This patch adds a return_max label for the two cases that need to set > the lux to TSL2X7X_LUX_CALC_OVER_FLOW and return. > > Signed-off-by: Brian Masney <masneyb@onstation.org> Sorry - don't like this last one. I think it hurts readability. Leave this as it was. Thanks Jonathan > --- > drivers/staging/iio/light/tsl2x7x.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c > index 42ed9c015aaf..898304d65f64 100644 > --- a/drivers/staging/iio/light/tsl2x7x.c > +++ b/drivers/staging/iio/light/tsl2x7x.c > @@ -364,10 +364,8 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) > chip->als_cur_info.als_ch0 = ch0; > chip->als_cur_info.als_ch1 = ch1; > > - if (ch0 >= chip->als_saturation || ch1 >= chip->als_saturation) { > - lux = TSL2X7X_LUX_CALC_OVER_FLOW; > + if (ch0 >= chip->als_saturation || ch1 >= chip->als_saturation) > goto return_max; > - } > > if (!ch0) { > /* have no data, so return LAST VALUE */ > @@ -418,11 +416,12 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) > lux = lux64; > lux = (lux + 500) / 1000; > > - if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) /* check for overflow */ > + if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) { /* check for overflow */ > +return_max: > lux = TSL2X7X_LUX_CALC_OVER_FLOW; > + } > > /* Update the structure with the latest lux. */ > -return_max: > chip->als_cur_info.lux = lux; > ret = lux; > -- To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, Oct 19, 2017 at 04:06:32PM -0400, Brian Masney wrote: > This patch adds a return_max label for the two cases that need to set > the lux to TSL2X7X_LUX_CALC_OVER_FLOW and return. > > Signed-off-by: Brian Masney <masneyb@onstation.org> > --- > drivers/staging/iio/light/tsl2x7x.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c > index 42ed9c015aaf..898304d65f64 100644 > --- a/drivers/staging/iio/light/tsl2x7x.c > +++ b/drivers/staging/iio/light/tsl2x7x.c > @@ -364,10 +364,8 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) > chip->als_cur_info.als_ch0 = ch0; > chip->als_cur_info.als_ch1 = ch1; > > - if (ch0 >= chip->als_saturation || ch1 >= chip->als_saturation) { > - lux = TSL2X7X_LUX_CALC_OVER_FLOW; > + if (ch0 >= chip->als_saturation || ch1 >= chip->als_saturation) > goto return_max; > - } > > if (!ch0) { > /* have no data, so return LAST VALUE */ > @@ -418,11 +416,12 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) > lux = lux64; > lux = (lux + 500) / 1000; > > - if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) /* check for overflow */ > + if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) { /* check for overflow */ > +return_max: > lux = TSL2X7X_LUX_CALC_OVER_FLOW; > + } Ugh... Wow. No. This terrible anti-pattern is spreading. Don't do this. regards, dan carpenter -- To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 42ed9c015aaf..898304d65f64 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -364,10 +364,8 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) chip->als_cur_info.als_ch0 = ch0; chip->als_cur_info.als_ch1 = ch1; - if (ch0 >= chip->als_saturation || ch1 >= chip->als_saturation) { - lux = TSL2X7X_LUX_CALC_OVER_FLOW; + if (ch0 >= chip->als_saturation || ch1 >= chip->als_saturation) goto return_max; - } if (!ch0) { /* have no data, so return LAST VALUE */ @@ -418,11 +416,12 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) lux = lux64; lux = (lux + 500) / 1000; - if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) /* check for overflow */ + if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) { /* check for overflow */ +return_max: lux = TSL2X7X_LUX_CALC_OVER_FLOW; + } /* Update the structure with the latest lux. */ -return_max: chip->als_cur_info.lux = lux; ret = lux;
This patch adds a return_max label for the two cases that need to set the lux to TSL2X7X_LUX_CALC_OVER_FLOW and return. Signed-off-by: Brian Masney <masneyb@onstation.org> --- drivers/staging/iio/light/tsl2x7x.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)