* [PATCH] iio:light:tsl2563: avoid flush_scheduled_work() usage
@ 2022-06-10 6:06 Tetsuo Handa
2022-06-12 14:52 ` [PATCH v2] iio:light:tsl2563: Replace flush_scheduled_work() with cancel_delayed_work_sync() Tetsuo Handa
0 siblings, 1 reply; 3+ messages in thread
From: Tetsuo Handa @ 2022-06-10 6:06 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen; +Cc: linux-iio
Use local wq in order to avoid flush_scheduled_work() usage.
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
Please see commit c4f135d643823a86 ("workqueue: Wrap flush_workqueue()
using a macro") for background.
This is a blind conversion, and is only compile tested.
drivers/iio/light/tsl2563.c | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c
index 0a278eea36ca..0739fced0d34 100644
--- a/drivers/iio/light/tsl2563.c
+++ b/drivers/iio/light/tsl2563.c
@@ -75,6 +75,8 @@
#define TSL2563_INT_LEVEL 0x10
#define TSL2563_INT_PERSIST(n) ((n) & 0x0F)
+static struct workqueue_struct *tsl2563_wq;
+
struct tsl2563_gainlevel_coeff {
u8 gaintime;
u16 min;
@@ -343,7 +345,7 @@ static int tsl2563_get_adc(struct tsl2563_chip *chip)
chip->data1 = tsl2563_normalize_adc(adc1, chip->gainlevel->gaintime);
if (!chip->int_enabled)
- schedule_delayed_work(&chip->poweroff_work, 5 * HZ);
+ queue_delayed_work(tsl2563_wq, &chip->poweroff_work, 5 * HZ);
ret = 0;
out:
@@ -660,7 +662,7 @@ static int tsl2563_write_interrupt_config(struct iio_dev *indio_dev,
chip->intr);
chip->int_enabled = false;
/* now the interrupt is not enabled, we can go to sleep */
- schedule_delayed_work(&chip->poweroff_work, 5 * HZ);
+ queue_delayed_work(tsl2563_wq, &chip->poweroff_work, 5 * HZ);
}
out:
mutex_unlock(&chip->lock);
@@ -781,7 +783,7 @@ static int tsl2563_probe(struct i2c_client *client,
INIT_DELAYED_WORK(&chip->poweroff_work, tsl2563_poweroff_work);
/* The interrupt cannot yet be enabled so this is fine without lock */
- schedule_delayed_work(&chip->poweroff_work, 5 * HZ);
+ queue_delayed_work(tsl2563_wq, &chip->poweroff_work, 5 * HZ);
err = iio_device_register(indio_dev);
if (err) {
@@ -808,7 +810,7 @@ static int tsl2563_remove(struct i2c_client *client)
chip->intr &= ~0x30;
i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | TSL2563_REG_INT,
chip->intr);
- flush_scheduled_work();
+ flush_workqueue(tsl2563_wq);
tsl2563_set_power(chip, 0);
return 0;
@@ -887,7 +889,27 @@ static struct i2c_driver tsl2563_i2c_driver = {
.remove = tsl2563_remove,
.id_table = tsl2563_id,
};
-module_i2c_driver(tsl2563_i2c_driver);
+
+static int __init tsl2563_init(void)
+{
+ int ret;
+
+ tsl2563_wq = alloc_workqueue("tsl2563_wq", 0, 0);
+ if (!tsl2563_wq)
+ return -ENOMEM;
+ ret = i2c_add_driver(&tsl2563_i2c_driver);
+ if (ret)
+ destroy_workqueue(tsl2563_wq);
+ return ret;
+}
+module_init(tsl2563_init);
+
+static void __exit tsl2563_exit(void)
+{
+ i2c_del_driver(&tsl2563_i2c_driver);
+ destroy_workqueue(tsl2563_wq);
+}
+module_exit(tsl2563_exit);
MODULE_AUTHOR("Nokia Corporation");
MODULE_DESCRIPTION("tsl2563 light sensor driver");
--
2.18.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v2] iio:light:tsl2563: Replace flush_scheduled_work() with cancel_delayed_work_sync().
2022-06-10 6:06 [PATCH] iio:light:tsl2563: avoid flush_scheduled_work() usage Tetsuo Handa
@ 2022-06-12 14:52 ` Tetsuo Handa
2022-06-18 13:52 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Tetsuo Handa @ 2022-06-12 14:52 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen; +Cc: linux-iio
Commit 9e61d901155bcd4e ("iio: light: tsl2563: Remove
flush_scheduled_work") replaced cancel_delayed_work() +
flush_scheduled_work() with cancel_delayed_work_sync() for only
tsl2563_probe() side.
Do the same thing for tsl2563_remove() side, which was added by
commit 388be4883952872b ("staging:iio: tsl2563 abi fixes and interrupt
handling").
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
Changes in v2:
Use cancel_delayed_work_sync() instead of introducing a dedicated WQ.
Please see commit c4f135d643823a86 ("workqueue: Wrap flush_workqueue()
using a macro") for background.
drivers/iio/light/tsl2563.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c
index 0a278eea36ca..4d89ac3a5bbc 100644
--- a/drivers/iio/light/tsl2563.c
+++ b/drivers/iio/light/tsl2563.c
@@ -803,12 +803,11 @@ static int tsl2563_remove(struct i2c_client *client)
iio_device_unregister(indio_dev);
if (!chip->int_enabled)
- cancel_delayed_work(&chip->poweroff_work);
+ cancel_delayed_work_sync(&chip->poweroff_work);
/* Ensure that interrupts are disabled - then flush any bottom halves */
chip->intr &= ~0x30;
i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | TSL2563_REG_INT,
chip->intr);
- flush_scheduled_work();
tsl2563_set_power(chip, 0);
return 0;
--
2.18.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] iio:light:tsl2563: Replace flush_scheduled_work() with cancel_delayed_work_sync().
2022-06-12 14:52 ` [PATCH v2] iio:light:tsl2563: Replace flush_scheduled_work() with cancel_delayed_work_sync() Tetsuo Handa
@ 2022-06-18 13:52 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2022-06-18 13:52 UTC (permalink / raw)
To: Tetsuo Handa; +Cc: Lars-Peter Clausen, linux-iio
On Sun, 12 Jun 2022 23:52:59 +0900
Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:
> Commit 9e61d901155bcd4e ("iio: light: tsl2563: Remove
> flush_scheduled_work") replaced cancel_delayed_work() +
> flush_scheduled_work() with cancel_delayed_work_sync() for only
> tsl2563_probe() side.
>
> Do the same thing for tsl2563_remove() side, which was added by
> commit 388be4883952872b ("staging:iio: tsl2563 abi fixes and interrupt
> handling").
>
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> ---
> Changes in v2:
> Use cancel_delayed_work_sync() instead of introducing a dedicated WQ.
Nice. This does the job without the complexity or overhead of a dedicated
work queue.
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to see if we missed anything.
Thanks,
Jonathqan
>
> Please see commit c4f135d643823a86 ("workqueue: Wrap flush_workqueue()
> using a macro") for background.
>
> drivers/iio/light/tsl2563.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c
> index 0a278eea36ca..4d89ac3a5bbc 100644
> --- a/drivers/iio/light/tsl2563.c
> +++ b/drivers/iio/light/tsl2563.c
> @@ -803,12 +803,11 @@ static int tsl2563_remove(struct i2c_client *client)
>
> iio_device_unregister(indio_dev);
> if (!chip->int_enabled)
> - cancel_delayed_work(&chip->poweroff_work);
> + cancel_delayed_work_sync(&chip->poweroff_work);
> /* Ensure that interrupts are disabled - then flush any bottom halves */
> chip->intr &= ~0x30;
> i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | TSL2563_REG_INT,
> chip->intr);
> - flush_scheduled_work();
> tsl2563_set_power(chip, 0);
>
> return 0;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-18 13:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-10 6:06 [PATCH] iio:light:tsl2563: avoid flush_scheduled_work() usage Tetsuo Handa
2022-06-12 14:52 ` [PATCH v2] iio:light:tsl2563: Replace flush_scheduled_work() with cancel_delayed_work_sync() Tetsuo Handa
2022-06-18 13:52 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox