[PATCH v14 3/3] drm/tinydrm: Add devres versions of of_find_backlight
Meghana Madhyastha
meghana.madhyastha at gmail.com
Sat Oct 21 11:59:04 UTC 2017
Add devm_of_find_backlight and the corresponding release
function because some drivers use devres versions of functions
for acquiring device resources.
Signed-off-by: Meghana Madhyastha <meghana.madhyastha at gmail.com>
---
Changes in v14:
- s/devm_backlight_get/devm_of_find_backlight/
- change commit message from requiring to acquiring
drivers/gpu/drm/tinydrm/mi0283qt.c | 2 +-
drivers/video/backlight/backlight.c | 31 +++++++++++++++++++++++++++++++
include/linux/backlight.h | 7 +++++++
3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c b/drivers/gpu/drm/tinydrm/mi0283qt.c
index 53ab5a0..568834a 100644
--- a/drivers/gpu/drm/tinydrm/mi0283qt.c
+++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
@@ -189,7 +189,7 @@ static int mi0283qt_probe(struct spi_device *spi)
if (IS_ERR(mipi->regulator))
return PTR_ERR(mipi->regulator);
- mipi->backlight = of_find_backlight(dev);
+ mipi->backlight = devm_of_find_backlight(dev);
if (IS_ERR(mipi->backlight))
return PTR_ERR(mipi->backlight);
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 76d46c3..4bb7bf3 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -617,6 +617,37 @@ struct backlight_device *of_find_backlight(struct device *dev)
}
EXPORT_SYMBOL(of_find_backlight);
+static void devm_backlight_put(void *data)
+{
+ backlight_put(data);
+}
+
+/**
+ * devm_of_find_backlight - Resource-managed of_find_backlight()
+ * @dev: Device
+ *
+ * Device managed version of of_find_backlight(). The reference on the backlight
+ * device is automatically dropped on driver detach.
+ */
+struct backlight_device *devm_of_find_backlight(struct device *dev)
+{
+ struct backlight_device *bd;
+ int ret;
+
+ bd = of_find_backlight(dev);
+ if (!bd)
+ return NULL;
+
+ ret = devm_add_action(dev, devm_backlight_put, bd);
+ if (ret) {
+ backlight_put(bd);
+ return ERR_PTR(ret);
+ }
+
+ return bd;
+}
+EXPORT_SYMBOL(devm_of_find_backlight);
+
static void __exit backlight_class_exit(void)
{
class_destroy(backlight_class);
diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index f98b684..a52bda0 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -214,11 +214,18 @@ of_find_backlight_by_node(struct device_node *node)
#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
struct backlight_device *of_find_backlight(struct device *dev);
+struct backlight_device *devm_of_find_backlight(struct device *dev);
#else
static inline struct backlight_device *of_find_backlight(struct device *dev)
{
return NULL;
}
+
+static inline struct backlight_device *
+devm_of_find_backlight(struct device *dev)
+{
+ return NULL;
+}
#endif
#endif
--
2.7.4
More information about the dri-devel
mailing list