From: Jonathan Cameron <jic23@kernel.org>
To: Akinobu Mita <akinobu.mita@gmail.com>
Cc: linux-iio@vger.kernel.org, "Stefan Brüns" <stefan.bruens@rwth-aachen.de>
Subject: Re: [PATCH] iio: adc: ina2xx: avoid kthread_stop() with stale task_struct
Date: Sat, 30 Jun 2018 18:40:49 +0100 [thread overview]
Message-ID: <20180630184049.47d10937@archlinux> (raw)
In-Reply-To: <1529852721-17828-1-git-send-email-akinobu.mita@gmail.com>
On Mon, 25 Jun 2018 00:05:21 +0900
Akinobu Mita <akinobu.mita@gmail.com> wrote:
> When the buffer is enabled for ina2xx driver, a dedicated kthread is
> invoked to capture mesurement data. When the buffer is disabled, the
> kthread is stopped.
>=20
> However if the kthread gets register access errors, it immediately exits
> and when the malfunctional buffer is disabled, the stale task_struct
> pointer is accessed as there is no kthread to be stopped.
>=20
> A similar issue in the usbip driver is prevented by kthread_get_run and
> kthread_stop_put helpers by increasing usage count of the task_struct.
> This change applies the same solution.
>=20
> Cc: Stefan Br=C3=BCns <stefan.bruens@rwth-aachen.de>
> Cc: Jonathan Cameron <jic23@kernel.org>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Seems fine, but this is a fix so should have an appropriate fixes
tag. Feel free to send one in reply to this thread rather than a v2.
Without a fixes tag it can be very hard to know exactly where
a patch 'should' apply. I also have little visibility on
how important backporting htis issue is. What would actually trigger
the issue and is it likely to be seen in the wild?
Thanks,
Jonathan
> ---
> drivers/iio/adc/ina2xx-adc.c | 17 +++++++++++++----
> 1 file changed, 13 insertions(+), 4 deletions(-)
>=20
> diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
> index 0635a79..d123962 100644
> --- a/drivers/iio/adc/ina2xx-adc.c
> +++ b/drivers/iio/adc/ina2xx-adc.c
> @@ -30,6 +30,7 @@
> #include <linux/module.h>
> #include <linux/of_device.h>
> #include <linux/regmap.h>
> +#include <linux/sched/task.h>
> #include <linux/util_macros.h>
> =20
> #include <linux/platform_data/ina2xx.h>
> @@ -826,6 +827,7 @@ static int ina2xx_buffer_enable(struct iio_dev *indio=
_dev)
> {
> struct ina2xx_chip_info *chip =3D iio_priv(indio_dev);
> unsigned int sampling_us =3D SAMPLING_PERIOD(chip);
> + struct task_struct *task;
> =20
> dev_dbg(&indio_dev->dev, "Enabling buffer w/ scan_mask %02x, freq =3D %=
d, avg =3D%u\n",
> (unsigned int)(*indio_dev->active_scan_mask),
> @@ -835,11 +837,17 @@ static int ina2xx_buffer_enable(struct iio_dev *ind=
io_dev)
> dev_dbg(&indio_dev->dev, "Async readout mode: %d\n",
> chip->allow_async_readout);
> =20
> - chip->task =3D kthread_run(ina2xx_capture_thread, (void *)indio_dev,
> - "%s:%d-%uus", indio_dev->name, indio_dev->id,
> - sampling_us);
> + task =3D kthread_create(ina2xx_capture_thread, (void *)indio_dev,
> + "%s:%d-%uus", indio_dev->name, indio_dev->id,
> + sampling_us);
> + if (IS_ERR(task))
> + return PTR_ERR(task);
> +
> + get_task_struct(task);
> + wake_up_process(task);
> + chip->task =3D task;
> =20
> - return PTR_ERR_OR_ZERO(chip->task);
> + return 0;
> }
> =20
> static int ina2xx_buffer_disable(struct iio_dev *indio_dev)
> @@ -848,6 +856,7 @@ static int ina2xx_buffer_disable(struct iio_dev *indi=
o_dev)
> =20
> if (chip->task) {
> kthread_stop(chip->task);
> + put_task_struct(chip->task);
> chip->task =3D NULL;
> }
> =20
next prev parent reply other threads:[~2018-06-30 17:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-24 15:05 [PATCH] iio: adc: ina2xx: avoid kthread_stop() with stale task_struct Akinobu Mita
2018-06-30 17:40 ` Jonathan Cameron [this message]
2018-07-02 8:44 ` Akinobu Mita
2018-07-07 16:07 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180630184049.47d10937@archlinux \
--to=jic23@kernel.org \
--cc=akinobu.mita@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=stefan.bruens@rwth-aachen.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).