Re: [PATCH 2/5] iio: Add support for LMP92001 ADC

From: jmondi
Date: Mon Aug 21 2017 - 13:38:14 EST


Hi Abhisit,

On Sun, Aug 20, 2017 at 11:31:41AM +0100, Jonathan Cameron wrote:
> On Fri, 18 Aug 2017 14:42:59 +0700
> Abhisit Sangjan <s.abhisit@xxxxxxxxx> wrote:
>
> > Hi Jmondi,
> >
> > After I removed those cases, I got warnings "no handled in switch".
> >
> > On Fri, Aug 18, 2017 at 10:15 AM, Abhisit Sangjan <s.abhisit@xxxxxxxxx>
> > wrote:
> >
> > > Hi Jmondi,
> > >
> > > On Fri, Aug 18, 2017 at 9:58 AM, jmondi <jacopo@xxxxxxxxxx> wrote:
> > >
> > >> Hi Abhisit,
> > >>
> > >> On Fri, Aug 18, 2017 at 09:34:16AM +0700, Abhisit Sangjan wrote:
> > >> > Hi Jmondi,
> > >> >
> > >> > Thank you for your recommend, I am testing the code will be send the new
> > >> > patch in soon.
> > >>
> > >> [snip]
> > >>
> > >> > > > > +
> > >> > > > > + switch (mask)
> > >> > > > > + {
> > >> > > > > + case IIO_CHAN_INFO_RAW:
> > >> > > > > + switch (channel->type) {
> > >> > > > > + case IIO_VOLTAGE:
> > >> > > > > + case IIO_TEMP:
> > >> > > > > + *val = code;
> > >> > > > > + return IIO_VAL_INT;
> > >> > > > > + default:
> > >> > > > > + break;
> > >> > > > > + }
> > >> > > > > + break;
> > >> > > > > + default:
> > >> > > > > + break;
> > >> > >
> > >> > > You can remove these default cases or return -EINVAL here.
> > >> > >
> > >> >
> > >> > Abhisit: Okay, I will remove it.
> > >> > Could you tell me in detail. Sorry, I do not understand the
> > >> > Technical.
> > >>
> > >> This can potentially be reduced to
> > >>
> > >> switch (mask) {
> > >> case IIO_CHAN_INFO_RAW:
> > >> switch (channel->type) {
> > >> case IIO_VOLTAGE:
> > >> case IIO_TEMP:
> > >> *val = code;
> > >> return IIO_VAL_INT;
> > >> }
> default:
> return -EINVAL;
> > >> }
> > >>
> get rid of the below.
> > >> return -EINVAL;
>
> Sorry, had forgotten about that warning!

My bad, as I have suggested but not compiled that code.
Thanks Jonathan!

>
> Jonathan
>
> > >>
> > >>
> > >> But that's definitely not a big deal, there are no optimization in
> > >> this code change, just less typing and less default: and break; here
> > >> and there
> > >>
> > >
> > > Abhisit: Thank you so much.
> > >
> >
> > Abhisit: If I remove those default cases, I got the warning. How do I would
> > do next to fix warning? Should I leave this code as it?
> >
> > # What have I changed.
> > diff --git a/drivers/iio/adc/lmp92001-adc.c b/drivers/iio/adc/lmp92001-adc.c
> > index 68f7a6c..ebc6423 100644
> > --- a/drivers/iio/adc/lmp92001-adc.c
> > +++ b/drivers/iio/adc/lmp92001-adc.c
> > @@ -92,12 +92,7 @@ static int lmp92001_read_raw(struct iio_dev *indio_dev,
> > case IIO_TEMP:
> > *val = code;
> > return IIO_VAL_INT;
> > - default:
> > - break;
> > }
> > - break;
> > - default:
> > - break;
> > }
> >
> > return -EINVAL;
> >
> > # Compilation.
> > CC drivers/iio/adc/lmp92001-adc.o
> > drivers/iio/adc/lmp92001-adc.c: In function âlmp92001_read_rawâ:
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_CURRENTâ not handled in switch [-Wswitch]
> > switch (channel->type) {
> > ^
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value âIIO_POWERâ
> > not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value âIIO_ACCELâ
> > not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_ANGL_VELâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value âIIO_MAGNâ
> > not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value âIIO_LIGHTâ
> > not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_INTENSITYâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_PROXIMITYâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value âIIO_INCLIâ
> > not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value âIIO_ROTâ
> > not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value âIIO_ANGLâ
> > not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_TIMESTAMPâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_CAPACITANCEâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_ALTVOLTAGEâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value âIIO_CCTâ
> > not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_PRESSUREâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_HUMIDITYRELATIVEâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_ACTIVITYâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value âIIO_STEPSâ
> > not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_ENERGYâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_DISTANCEâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_VELOCITYâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_CONCENTRATIONâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_RESISTANCEâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value âIIO_PHâ
> > not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_UVINDEXâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_ELECTRICALCONDUCTIVITYâ not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value âIIO_COUNTâ
> > not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value âIIO_INDEXâ
> > not handled in switch [-Wswitch]
> > drivers/iio/adc/lmp92001-adc.c:90:3: warning: enumeration value
> > âIIO_GRAVITYâ not handled in switch [-Wswitch]
> >
> >
> > >
> > >
> > >
>