mirror of
https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux
synced 2025-09-14 16:46:19 +10:00
gpiolib: Introduce gpio_device_get() and gpio_device_put()
Introduce gpio_device_get() and gpio_device_put() helpers and convert existing users. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
This commit is contained in:
parent
f2527d8f56
commit
dc0989e3aa
@ -321,7 +321,7 @@ static void linehandle_free(struct linehandle_state *lh)
|
|||||||
if (lh->descs[i])
|
if (lh->descs[i])
|
||||||
gpiod_free(lh->descs[i]);
|
gpiod_free(lh->descs[i]);
|
||||||
kfree(lh->label);
|
kfree(lh->label);
|
||||||
put_device(&lh->gdev->dev);
|
gpio_device_put(lh->gdev);
|
||||||
kfree(lh);
|
kfree(lh);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,8 +363,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
|
|||||||
lh = kzalloc(sizeof(*lh), GFP_KERNEL);
|
lh = kzalloc(sizeof(*lh), GFP_KERNEL);
|
||||||
if (!lh)
|
if (!lh)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
lh->gdev = gdev;
|
lh->gdev = gpio_device_get(gdev);
|
||||||
get_device(&gdev->dev);
|
|
||||||
|
|
||||||
if (handlereq.consumer_label[0] != '\0') {
|
if (handlereq.consumer_label[0] != '\0') {
|
||||||
/* label is only initialized if consumer_label is set */
|
/* label is only initialized if consumer_label is set */
|
||||||
@ -1576,7 +1575,7 @@ static void linereq_free(struct linereq *lr)
|
|||||||
}
|
}
|
||||||
kfifo_free(&lr->events);
|
kfifo_free(&lr->events);
|
||||||
kfree(lr->label);
|
kfree(lr->label);
|
||||||
put_device(&lr->gdev->dev);
|
gpio_device_put(lr->gdev);
|
||||||
kfree(lr);
|
kfree(lr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1646,8 +1645,7 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip)
|
|||||||
if (!lr)
|
if (!lr)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
lr->gdev = gdev;
|
lr->gdev = gpio_device_get(gdev);
|
||||||
get_device(&gdev->dev);
|
|
||||||
|
|
||||||
for (i = 0; i < ulr.num_lines; i++) {
|
for (i = 0; i < ulr.num_lines; i++) {
|
||||||
lr->lines[i].req = lr;
|
lr->lines[i].req = lr;
|
||||||
@ -1916,7 +1914,7 @@ static void lineevent_free(struct lineevent_state *le)
|
|||||||
if (le->desc)
|
if (le->desc)
|
||||||
gpiod_free(le->desc);
|
gpiod_free(le->desc);
|
||||||
kfree(le->label);
|
kfree(le->label);
|
||||||
put_device(&le->gdev->dev);
|
gpio_device_put(le->gdev);
|
||||||
kfree(le);
|
kfree(le);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2094,8 +2092,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
|
|||||||
le = kzalloc(sizeof(*le), GFP_KERNEL);
|
le = kzalloc(sizeof(*le), GFP_KERNEL);
|
||||||
if (!le)
|
if (!le)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
le->gdev = gdev;
|
le->gdev = gpio_device_get(gdev);
|
||||||
get_device(&gdev->dev);
|
|
||||||
|
|
||||||
if (eventreq.consumer_label[0] != '\0') {
|
if (eventreq.consumer_label[0] != '\0') {
|
||||||
/* label is only initialized if consumer_label is set */
|
/* label is only initialized if consumer_label is set */
|
||||||
@ -2671,7 +2668,7 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file)
|
|||||||
|
|
||||||
init_waitqueue_head(&cdev->wait);
|
init_waitqueue_head(&cdev->wait);
|
||||||
INIT_KFIFO(cdev->events);
|
INIT_KFIFO(cdev->events);
|
||||||
cdev->gdev = gdev;
|
cdev->gdev = gpio_device_get(gdev);
|
||||||
|
|
||||||
cdev->lineinfo_changed_nb.notifier_call = lineinfo_changed_notify;
|
cdev->lineinfo_changed_nb.notifier_call = lineinfo_changed_notify;
|
||||||
ret = blocking_notifier_chain_register(&gdev->notifier,
|
ret = blocking_notifier_chain_register(&gdev->notifier,
|
||||||
@ -2679,7 +2676,6 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file)
|
|||||||
if (ret)
|
if (ret)
|
||||||
goto out_free_bitmap;
|
goto out_free_bitmap;
|
||||||
|
|
||||||
get_device(&gdev->dev);
|
|
||||||
file->private_data = cdev;
|
file->private_data = cdev;
|
||||||
|
|
||||||
ret = nonseekable_open(inode, file);
|
ret = nonseekable_open(inode, file);
|
||||||
@ -2694,6 +2690,7 @@ out_unregister_notifier:
|
|||||||
blocking_notifier_chain_unregister(&gdev->notifier,
|
blocking_notifier_chain_unregister(&gdev->notifier,
|
||||||
&cdev->lineinfo_changed_nb);
|
&cdev->lineinfo_changed_nb);
|
||||||
out_free_bitmap:
|
out_free_bitmap:
|
||||||
|
gpio_device_put(gdev);
|
||||||
bitmap_free(cdev->watched_lines);
|
bitmap_free(cdev->watched_lines);
|
||||||
out_free_cdev:
|
out_free_cdev:
|
||||||
kfree(cdev);
|
kfree(cdev);
|
||||||
@ -2716,7 +2713,7 @@ static int gpio_chrdev_release(struct inode *inode, struct file *file)
|
|||||||
bitmap_free(cdev->watched_lines);
|
bitmap_free(cdev->watched_lines);
|
||||||
blocking_notifier_chain_unregister(&gdev->notifier,
|
blocking_notifier_chain_unregister(&gdev->notifier,
|
||||||
&cdev->lineinfo_changed_nb);
|
&cdev->lineinfo_changed_nb);
|
||||||
put_device(&gdev->dev);
|
gpio_device_put(gdev);
|
||||||
kfree(cdev);
|
kfree(cdev);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -882,7 +882,7 @@ err_free_gpiochip_mask:
|
|||||||
gpiochip_free_valid_mask(gc);
|
gpiochip_free_valid_mask(gc);
|
||||||
if (gdev->dev.release) {
|
if (gdev->dev.release) {
|
||||||
/* release() has been registered by gpiochip_setup_dev() */
|
/* release() has been registered by gpiochip_setup_dev() */
|
||||||
put_device(&gdev->dev);
|
gpio_device_put(gdev);
|
||||||
goto err_print_message;
|
goto err_print_message;
|
||||||
}
|
}
|
||||||
err_remove_from_list:
|
err_remove_from_list:
|
||||||
@ -972,7 +972,7 @@ void gpiochip_remove(struct gpio_chip *gc)
|
|||||||
*/
|
*/
|
||||||
gcdev_unregister(gdev);
|
gcdev_unregister(gdev);
|
||||||
up_write(&gdev->sem);
|
up_write(&gdev->sem);
|
||||||
put_device(&gdev->dev);
|
gpio_device_put(gdev);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(gpiochip_remove);
|
EXPORT_SYMBOL_GPL(gpiochip_remove);
|
||||||
|
|
||||||
@ -2057,17 +2057,15 @@ static int validate_desc(const struct gpio_desc *desc, const char *func)
|
|||||||
int gpiod_request(struct gpio_desc *desc, const char *label)
|
int gpiod_request(struct gpio_desc *desc, const char *label)
|
||||||
{
|
{
|
||||||
int ret = -EPROBE_DEFER;
|
int ret = -EPROBE_DEFER;
|
||||||
struct gpio_device *gdev;
|
|
||||||
|
|
||||||
VALIDATE_DESC(desc);
|
VALIDATE_DESC(desc);
|
||||||
gdev = desc->gdev;
|
|
||||||
|
|
||||||
if (try_module_get(gdev->owner)) {
|
if (try_module_get(desc->gdev->owner)) {
|
||||||
ret = gpiod_request_commit(desc, label);
|
ret = gpiod_request_commit(desc, label);
|
||||||
if (ret)
|
if (ret)
|
||||||
module_put(gdev->owner);
|
module_put(desc->gdev->owner);
|
||||||
else
|
else
|
||||||
get_device(&gdev->dev);
|
gpio_device_get(desc->gdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
@ -2128,7 +2126,7 @@ void gpiod_free(struct gpio_desc *desc)
|
|||||||
{
|
{
|
||||||
if (desc && desc->gdev && gpiod_free_commit(desc)) {
|
if (desc && desc->gdev && gpiod_free_commit(desc)) {
|
||||||
module_put(desc->gdev->owner);
|
module_put(desc->gdev->owner);
|
||||||
put_device(&desc->gdev->dev);
|
gpio_device_put(desc->gdev);
|
||||||
} else {
|
} else {
|
||||||
WARN_ON(extra_checks);
|
WARN_ON(extra_checks);
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,16 @@ static inline struct gpio_device *to_gpio_device(struct device *dev)
|
|||||||
return container_of(dev, struct gpio_device, dev);
|
return container_of(dev, struct gpio_device, dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct gpio_device *gpio_device_get(struct gpio_device *gdev)
|
||||||
|
{
|
||||||
|
return to_gpio_device(get_device(&gdev->dev));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void gpio_device_put(struct gpio_device *gdev)
|
||||||
|
{
|
||||||
|
put_device(&gdev->dev);
|
||||||
|
}
|
||||||
|
|
||||||
/* gpio suffixes used for ACPI and device tree lookup */
|
/* gpio suffixes used for ACPI and device tree lookup */
|
||||||
static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" };
|
static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" };
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user