Message ID | 20200325100112.85107-1-alexandru.ardelean@analog.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2] iio: buffer: Don't allow buffers without any channels enabled to be activated | expand |
On Wed, 2020-03-25 at 12:01 +0200, Alexandru Ardelean wrote: > From: Lars-Peter Clausen <lars@metafoo.de> > > Before activating a buffer make sure that at least one channel is enabled. > Activating a buffer with 0 channels enabled doesn't make too much sense and > disallowing this case makes sure that individual driver don't have to add > special case code to handle it. > oops, i goof-ed peter's email on this send; [ copy + paste err ] should be fixed now; > Currently, without this patch enabling a buffer is possible and no error is > produced. With this patch -EINVAL is returned. > > An example of execution with this patch and some instrumented print-code: > root@analog:~# cd /sys/bus/iio/devices/iio\:device3/buffer > root@analog:/sys/bus/iio/devices/iio:device3/buffer# echo 1 > enable > 0: iio_verify_update 748 indio_dev->masklength 2 *insert_buffer->scan_mask > 00000000 > 1: iio_verify_update 753 > 2:__iio_update_buffers 1115 ret -22 > 3: iio_buffer_store_enable 1241 ret -22 > -bash: echo: write error: Invalid argument > 1, 2 & 3 are exit-error paths. 0 the first print in iio_verify_update() > rergardless of error path. > > Without this patch (and same instrumented print-code): > root@analog:~# cd /sys/bus/iio/devices/iio\:device3/buffer > root@analog:/sys/bus/iio/devices/iio:device3/buffer# echo 1 > enable > 0: iio_verify_update 748 indio_dev->masklength 2 *insert_buffer->scan_mask > 00000000 > root@analog:/sys/bus/iio/devices/iio:device3/buffer# > Buffer is enabled with no error. > > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> > --- > > Changelog v1 -> v2: > * moved check in iio_verify_update() > * added dev_dbg() message; should help some folks understand the message > * documented steps to reproduce > * added Fixes tag; hopefully the tag is the good one; if needed, it can be > dropped; this has been around for ~8 years; no idea if it's worth > backporting > > drivers/iio/industrialio-buffer.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio- > buffer.c > index 5ff34ce8b6a2..e6fa1a4e135d 100644 > --- a/drivers/iio/industrialio-buffer.c > +++ b/drivers/iio/industrialio-buffer.c > @@ -686,6 +686,13 @@ static int iio_verify_update(struct iio_dev *indio_dev, > bool scan_timestamp; > unsigned int modes; > > + if (insert_buffer && > + bitmap_empty(insert_buffer->scan_mask, indio_dev->masklength)) { > + dev_dbg(&indio_dev->dev, > + "At least one scan element must be enabled first\n"); > + return -EINVAL; > + } > + > memset(config, 0, sizeof(*config)); > config->watermark = ~0; >
On Wed, Mar 25, 2020 at 12:02 PM Alexandru Ardelean <alexandru.ardelean@analog.com> wrote: > > From: Lars-Peter Clausen <lars@metafoo.de> > > Before activating a buffer make sure that at least one channel is enabled. > Activating a buffer with 0 channels enabled doesn't make too much sense and > disallowing this case makes sure that individual driver don't have to add > special case code to handle it. > > Currently, without this patch enabling a buffer is possible and no error is > produced. With this patch -EINVAL is returned. > > An example of execution with this patch and some instrumented print-code: > root@analog:~# cd /sys/bus/iio/devices/iio\:device3/buffer > root@analog:/sys/bus/iio/devices/iio:device3/buffer# echo 1 > enable > 0: iio_verify_update 748 indio_dev->masklength 2 *insert_buffer->scan_mask 00000000 > 1: iio_verify_update 753 > 2:__iio_update_buffers 1115 ret -22 > 3: iio_buffer_store_enable 1241 ret -22 > -bash: echo: write error: Invalid argument > 1, 2 & 3 are exit-error paths. 0 the first print in iio_verify_update() > rergardless of error path. > > Without this patch (and same instrumented print-code): > root@analog:~# cd /sys/bus/iio/devices/iio\:device3/buffer > root@analog:/sys/bus/iio/devices/iio:device3/buffer# echo 1 > enable > 0: iio_verify_update 748 indio_dev->masklength 2 *insert_buffer->scan_mask 00000000 > root@analog:/sys/bus/iio/devices/iio:device3/buffer# > Buffer is enabled with no error. > > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> > --- > > Changelog v1 -> v2: > * moved check in iio_verify_update() > * added dev_dbg() message; should help some folks understand the message > * documented steps to reproduce > * added Fixes tag; hopefully the tag is the good one; if needed, it can be > dropped; this has been around for ~8 years; no idea if it's worth > backporting Where? > > drivers/iio/industrialio-buffer.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c > index 5ff34ce8b6a2..e6fa1a4e135d 100644 > --- a/drivers/iio/industrialio-buffer.c > +++ b/drivers/iio/industrialio-buffer.c > @@ -686,6 +686,13 @@ static int iio_verify_update(struct iio_dev *indio_dev, > bool scan_timestamp; > unsigned int modes; > > + if (insert_buffer && > + bitmap_empty(insert_buffer->scan_mask, indio_dev->masklength)) { > + dev_dbg(&indio_dev->dev, > + "At least one scan element must be enabled first\n"); > + return -EINVAL; > + } > + > memset(config, 0, sizeof(*config)); > config->watermark = ~0; > > -- > 2.17.1 >
On Wed, 2020-03-25 at 17:57 +0200, Andy Shevchenko wrote: > [External] > > On Wed, Mar 25, 2020 at 12:02 PM Alexandru Ardelean > <alexandru.ardelean@analog.com> wrote: > > From: Lars-Peter Clausen <lars@metafoo.de> > > > > Before activating a buffer make sure that at least one channel is enabled. > > Activating a buffer with 0 channels enabled doesn't make too much sense and > > disallowing this case makes sure that individual driver don't have to add > > special case code to handle it. > > > > Currently, without this patch enabling a buffer is possible and no error is > > produced. With this patch -EINVAL is returned. > > > > An example of execution with this patch and some instrumented print-code: > > root@analog:~# cd /sys/bus/iio/devices/iio\:device3/buffer > > root@analog:/sys/bus/iio/devices/iio:device3/buffer# echo 1 > enable > > 0: iio_verify_update 748 indio_dev->masklength 2 *insert_buffer- > > >scan_mask 00000000 > > 1: iio_verify_update 753 > > 2:__iio_update_buffers 1115 ret -22 > > 3: iio_buffer_store_enable 1241 ret -22 > > -bash: echo: write error: Invalid argument > > 1, 2 & 3 are exit-error paths. 0 the first print in iio_verify_update() > > rergardless of error path. > > > > Without this patch (and same instrumented print-code): > > root@analog:~# cd /sys/bus/iio/devices/iio\:device3/buffer > > root@analog:/sys/bus/iio/devices/iio:device3/buffer# echo 1 > enable > > 0: iio_verify_update 748 indio_dev->masklength 2 *insert_buffer- > > >scan_mask 00000000 > > root@analog:/sys/bus/iio/devices/iio:device3/buffer# > > Buffer is enabled with no error. > > > > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> > > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> > > --- > > > > Changelog v1 -> v2: > > * moved check in iio_verify_update() > > * added dev_dbg() message; should help some folks understand the message > > * documented steps to reproduce > > * added Fixes tag; hopefully the tag is the good one; if needed, it can be > > dropped; this has been around for ~8 years; no idea if it's worth > > backporting > > Where? stable/fixes/lts-kernels don't have a really good clue about where these things need backporting; > > > drivers/iio/industrialio-buffer.c | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio- > > buffer.c > > index 5ff34ce8b6a2..e6fa1a4e135d 100644 > > --- a/drivers/iio/industrialio-buffer.c > > +++ b/drivers/iio/industrialio-buffer.c > > @@ -686,6 +686,13 @@ static int iio_verify_update(struct iio_dev *indio_dev, > > bool scan_timestamp; > > unsigned int modes; > > > > + if (insert_buffer && > > + bitmap_empty(insert_buffer->scan_mask, indio_dev->masklength)) { > > + dev_dbg(&indio_dev->dev, > > + "At least one scan element must be enabled > > first\n"); > > + return -EINVAL; > > + } > > + > > memset(config, 0, sizeof(*config)); > > config->watermark = ~0; > > > > -- > > 2.17.1 > > > >
On 3/26/20 8:42 AM, Ardelean, Alexandru wrote: > On Wed, 2020-03-25 at 17:57 +0200, Andy Shevchenko wrote: >> [External] >> >> On Wed, Mar 25, 2020 at 12:02 PM Alexandru Ardelean >> <alexandru.ardelean@analog.com> wrote: >>> From: Lars-Peter Clausen <lars@metafoo.de> >>> >>> Before activating a buffer make sure that at least one channel is enabled. >>> Activating a buffer with 0 channels enabled doesn't make too much sense and >>> disallowing this case makes sure that individual driver don't have to add >>> special case code to handle it. >>> >>> Currently, without this patch enabling a buffer is possible and no error is >>> produced. With this patch -EINVAL is returned. >>> >>> An example of execution with this patch and some instrumented print-code: >>> root@analog:~# cd /sys/bus/iio/devices/iio\:device3/buffer >>> root@analog:/sys/bus/iio/devices/iio:device3/buffer# echo 1 > enable >>> 0: iio_verify_update 748 indio_dev->masklength 2 *insert_buffer- >>>> scan_mask 00000000 >>> 1: iio_verify_update 753 >>> 2:__iio_update_buffers 1115 ret -22 >>> 3: iio_buffer_store_enable 1241 ret -22 >>> -bash: echo: write error: Invalid argument >>> 1, 2 & 3 are exit-error paths. 0 the first print in iio_verify_update() >>> rergardless of error path. >>> >>> Without this patch (and same instrumented print-code): >>> root@analog:~# cd /sys/bus/iio/devices/iio\:device3/buffer >>> root@analog:/sys/bus/iio/devices/iio:device3/buffer# echo 1 > enable >>> 0: iio_verify_update 748 indio_dev->masklength 2 *insert_buffer- >>>> scan_mask 00000000 >>> root@analog:/sys/bus/iio/devices/iio:device3/buffer# >>> Buffer is enabled with no error. >>> >>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> >>> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> >>> --- >>> >>> Changelog v1 -> v2: >>> * moved check in iio_verify_update() >>> * added dev_dbg() message; should help some folks understand the message >>> * documented steps to reproduce >>> * added Fixes tag; hopefully the tag is the good one; if needed, it can be >>> dropped; this has been around for ~8 years; no idea if it's worth >>> backporting >> Where? > stable/fixes/lts-kernels > don't have a really good clue about where these things need backporting; What Andy means is that there is no Fixes tag :)
On Thu, 2020-03-26 at 08:44 +0100, Lars-Peter Clausen wrote: > [External] > > On 3/26/20 8:42 AM, Ardelean, Alexandru wrote: > > On Wed, 2020-03-25 at 17:57 +0200, Andy Shevchenko wrote: > > > [External] > > > > > > On Wed, Mar 25, 2020 at 12:02 PM Alexandru Ardelean > > > <alexandru.ardelean@analog.com> wrote: > > > > From: Lars-Peter Clausen <lars@metafoo.de> > > > > > > > > Before activating a buffer make sure that at least one channel is > > > > enabled. > > > > Activating a buffer with 0 channels enabled doesn't make too much sense > > > > and > > > > disallowing this case makes sure that individual driver don't have to > > > > add > > > > special case code to handle it. > > > > > > > > Currently, without this patch enabling a buffer is possible and no error > > > > is > > > > produced. With this patch -EINVAL is returned. > > > > > > > > An example of execution with this patch and some instrumented print- > > > > code: > > > > root@analog:~# cd /sys/bus/iio/devices/iio\:device3/buffer > > > > root@analog:/sys/bus/iio/devices/iio:device3/buffer# echo 1 > enable > > > > 0: iio_verify_update 748 indio_dev->masklength 2 *insert_buffer- > > > > > scan_mask 00000000 > > > > 1: iio_verify_update 753 > > > > 2:__iio_update_buffers 1115 ret -22 > > > > 3: iio_buffer_store_enable 1241 ret -22 > > > > -bash: echo: write error: Invalid argument > > > > 1, 2 & 3 are exit-error paths. 0 the first print in iio_verify_update() > > > > rergardless of error path. > > > > > > > > Without this patch (and same instrumented print-code): > > > > root@analog:~# cd /sys/bus/iio/devices/iio\:device3/buffer > > > > root@analog:/sys/bus/iio/devices/iio:device3/buffer# echo 1 > enable > > > > 0: iio_verify_update 748 indio_dev->masklength 2 *insert_buffer- > > > > > scan_mask 00000000 > > > > root@analog:/sys/bus/iio/devices/iio:device3/buffer# > > > > Buffer is enabled with no error. > > > > > > > > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> > > > > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> > > > > --- > > > > > > > > Changelog v1 -> v2: > > > > * moved check in iio_verify_update() > > > > * added dev_dbg() message; should help some folks understand the message > > > > * documented steps to reproduce > > > > * added Fixes tag; hopefully the tag is the good one; if needed, it can > > > > be > > > > dropped; this has been around for ~8 years; no idea if it's worth > > > > backporting > > > Where? > > stable/fixes/lts-kernels > > don't have a really good clue about where these things need backporting; > What Andy means is that there is no Fixes tag :) oh crap.... i added one but seem to have lost it when moving the patch to the server from where i do git-send i'll add one;
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index 5ff34ce8b6a2..e6fa1a4e135d 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -686,6 +686,13 @@ static int iio_verify_update(struct iio_dev *indio_dev, bool scan_timestamp; unsigned int modes; + if (insert_buffer && + bitmap_empty(insert_buffer->scan_mask, indio_dev->masklength)) { + dev_dbg(&indio_dev->dev, + "At least one scan element must be enabled first\n"); + return -EINVAL; + } + memset(config, 0, sizeof(*config)); config->watermark = ~0;