Struct gpio_device now provides a revocable provider to the underlying struct gpio_chip. Leverage revocable for lineinfo_changed_notify so that it doesn't need to handle the synchronization by accessing the SRCU explicitly.
Signed-off-by: Tzung-Bi Shih <[email protected]> --- drivers/gpio/gpiolib-cdev.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 54150d718931..1a4dde56dc0c 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2522,6 +2522,7 @@ struct lineinfo_changed_ctx { struct gpio_v2_line_info_changed chg; struct gpio_device *gdev; struct gpio_chardev_data *cdev; + struct revocable *chip_rev; }; static void lineinfo_changed_func(struct work_struct *work) @@ -2538,12 +2539,9 @@ static void lineinfo_changed_func(struct work_struct *work) * Pin functions are in general much more static and while it's * not 100% bullet-proof, it's good enough for most cases. */ - scoped_guard(srcu, &ctx->gdev->srcu) { - gc = srcu_dereference(ctx->gdev->chip, &ctx->gdev->srcu); - if (gc && - !pinctrl_gpio_can_use_line(gc, ctx->chg.info.offset)) - ctx->chg.info.flags |= GPIO_V2_LINE_FLAG_USED; - } + REVOCABLE_TRY_ACCESS_WITH(ctx->chip_rev, gc); + if (gc && !pinctrl_gpio_can_use_line(gc, ctx->chg.info.offset)) + ctx->chg.info.flags |= GPIO_V2_LINE_FLAG_USED; } ret = kfifo_in_spinlocked(&ctx->cdev->events, &ctx->chg, 1, @@ -2553,6 +2551,7 @@ static void lineinfo_changed_func(struct work_struct *work) else pr_debug_ratelimited("lineinfo event FIFO is full - event dropped\n"); + revocable_free(ctx->chip_rev); gpio_device_put(ctx->gdev); fput(ctx->cdev->fp); kfree(ctx); @@ -2599,11 +2598,19 @@ static int lineinfo_changed_notify(struct notifier_block *nb, /* Keep the GPIO device alive until we emit the event. */ ctx->gdev = gpio_device_get(desc->gdev); ctx->cdev = cdev; + ctx->chip_rev = revocable_alloc(desc->gdev->chip_rp); + if (!ctx->chip_rev) { + pr_err("Failed to allocate memory for revocable handle\n"); + goto err_put_device; + } INIT_WORK(&ctx->work, lineinfo_changed_func); queue_work(ctx->gdev->line_state_wq, &ctx->work); return NOTIFY_OK; +err_put_device: + gpio_device_put(desc->gdev); + kfree(ctx); err_put_fp: fput(fp); return NOTIFY_DONE; -- 2.52.0.457.g6b5491de43-goog
