summaryrefslogtreecommitdiff
path: root/drivers/gpio/gpio-aggregator.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2025-03-07 07:49:23 -1000
committerLinus Torvalds <torvalds@linux-foundation.org>2025-03-07 07:49:23 -1000
commit1222390d138d1f375fe28a9a052780009d2ce6ef (patch)
tree234482fe35f837c2d5f51ce24ac39c4ffbd74733 /drivers/gpio/gpio-aggregator.c
parent8aed61b8334e00f4fe5de9f2df1cd183dc328a9d (diff)
parent391b41f983bf7ff853de44704d8e14e7cc648a9b (diff)
Merge tag 'gpio-fixes-for-v6.14-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux
Pull gpio fixes from Bartosz Golaszewski: - protect gpio-aggregator against module unload - use raw spinlock in gpio-rcar to fix a lockdep splat - fix OF node leak in gpio-rcar * tag 'gpio-fixes-for-v6.14-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: gpio: rcar: Fix missing of_node_put() call gpio: rcar: Use raw_spinlock to protect register access gpio: aggregator: protect driver attr handlers against module unload
Diffstat (limited to 'drivers/gpio/gpio-aggregator.c')
-rw-r--r--drivers/gpio/gpio-aggregator.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
index 65f41cc3eafc..d668ddb2e81d 100644
--- a/drivers/gpio/gpio-aggregator.c
+++ b/drivers/gpio/gpio-aggregator.c
@@ -119,10 +119,15 @@ static ssize_t new_device_store(struct device_driver *driver, const char *buf,
struct platform_device *pdev;
int res, id;
+ if (!try_module_get(THIS_MODULE))
+ return -ENOENT;
+
/* kernfs guarantees string termination, so count + 1 is safe */
aggr = kzalloc(sizeof(*aggr) + count + 1, GFP_KERNEL);
- if (!aggr)
- return -ENOMEM;
+ if (!aggr) {
+ res = -ENOMEM;
+ goto put_module;
+ }
memcpy(aggr->args, buf, count + 1);
@@ -161,6 +166,7 @@ static ssize_t new_device_store(struct device_driver *driver, const char *buf,
}
aggr->pdev = pdev;
+ module_put(THIS_MODULE);
return count;
remove_table:
@@ -175,6 +181,8 @@ free_table:
kfree(aggr->lookups);
free_ga:
kfree(aggr);
+put_module:
+ module_put(THIS_MODULE);
return res;
}
@@ -203,13 +211,19 @@ static ssize_t delete_device_store(struct device_driver *driver,
if (error)
return error;
+ if (!try_module_get(THIS_MODULE))
+ return -ENOENT;
+
mutex_lock(&gpio_aggregator_lock);
aggr = idr_remove(&gpio_aggregator_idr, id);
mutex_unlock(&gpio_aggregator_lock);
- if (!aggr)
+ if (!aggr) {
+ module_put(THIS_MODULE);
return -ENOENT;
+ }
gpio_aggregator_free(aggr);
+ module_put(THIS_MODULE);
return count;
}
static DRIVER_ATTR_WO(delete_device);