Re: [PATCH 02/10] iio: dummy: Use automatic lock and direct mode cleanup.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> > @@ -436,10 +431,10 @@ static int iio_dummy_write_raw(struct iio_dev *indio_dev,
> >                         if (chan->output == 0)
> >                                 return -EINVAL;
> >
> > -                       /* Locking not required as writing single value */
> > -                       mutex_lock(&st->lock);
> > -                       st->dac_val = val;
> > -                       mutex_unlock(&st->lock);
> > +                       scoped_guard(mutex, &st->lock) {
> > +                               /* Locking not required as writing single value */
> > +                               st->dac_val = val;
> > +                       }
> >                         return 0;
> >                 default:
> >                         return -EINVAL;
> > @@ -447,9 +442,9 @@ static int iio_dummy_write_raw(struct iio_dev *indio_dev,
> >         case IIO_CHAN_INFO_PROCESSED:
> >                 switch (chan->type) {
> >                 case IIO_STEPS:
> > -                       mutex_lock(&st->lock);
> > -                       st->steps = val;
> > -                       mutex_unlock(&st->lock);
> > +                       scoped_guard(mutex, &st->lock) {
> > +                               st->steps = val;
> > +                       }
> >                         return 0;
> >                 case IIO_ACTIVITY:
> >                         if (val < 0)
> > @@ -470,30 +465,29 @@ static int iio_dummy_write_raw(struct iio_dev *indio_dev,
> >                 default:
> >                         return -EINVAL;
> >                 }
> > -       case IIO_CHAN_INFO_CALIBSCALE:
> > -               mutex_lock(&st->lock);
> > +       case IIO_CHAN_INFO_CALIBSCALE: {
> > +               guard(mutex)(&st->lock);
> >                 /* Compare against table - hard matching here */
> >                 for (i = 0; i < ARRAY_SIZE(dummy_scales); i++)
> >                         if (val == dummy_scales[i].val &&
> >                             val2 == dummy_scales[i].val2)
> >                                 break;
> >                 if (i == ARRAY_SIZE(dummy_scales))
> > -                       ret = -EINVAL;
> > -               else
> > -                       st->accel_calibscale = &dummy_scales[i];
> > -               mutex_unlock(&st->lock);
> > +                       return  -EINVAL;
> > +               st->accel_calibscale = &dummy_scales[i];
> >                 return ret;  
> 
> Can we change this to `return 0;` and get rid of the `ret = 0`
> initialization at the beginning of the function?

Yes. That would make sense.

> 
> > +       }





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux