[PATCH v13 3/3] drm/tinydrm: Add devres versions of backlight_get
Meghana Madhyastha
meghana.madhyastha at gmail.com
Fri Oct 13 10:42:55 UTC 2017
Add devm_backlight_get and the corresponding release
function because some drivers use devres versions of functions
for requiring device resources.
Signed-off-by: Meghana Madhyastha <meghana.madhyastha at gmail.com>
---
Changes in v13:
-Add devm_backlight_put to backlight.c
drivers/gpu/drm/tinydrm/mi0283qt.c | 2 +-
drivers/video/backlight/backlight.c | 31 +++++++++++++++++++++++++++++++
include/linux/backlight.h | 6 ++++++
3 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c b/drivers/gpu/drm/tinydrm/mi0283qt.c
index a932185..e3e7583 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 = backlight_get(dev);
+ mipi->backlight = devm_backlight_get(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 c4e94d0..b6c505a 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -617,6 +617,37 @@ struct backlight_device *backlight_get(struct device *dev)
}
EXPORT_SYMBOL(backlight_get);
+static void devm_backlight_put(void *data)
+{
+ backlight_put(data);
+}
+
+/**
+ * devm_backlight_get - Resource-managed backlight_get()
+ * @dev: Device
+ *
+ * Device managed version of backlight_get(). The reference on the backlight
+ * device is automatically dropped on driver detach.
+ */
+struct backlight_device *devm_backlight_get(struct device *dev)
+{
+ struct backlight_device *bd;
+ int ret;
+
+ bd = backlight_get(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_backlight_get);
+
static void __exit backlight_class_exit(void)
{
class_destroy(backlight_class);
diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index 987a6d7..8db9ba9 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -214,11 +214,17 @@ of_find_backlight_by_node(struct device_node *node)
#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
struct backlight_device *backlight_get(struct device *dev);
+struct backlight_device *devm_backlight_get(struct device *dev);
#else
static inline struct backlight_device *backlight_get(struct device *dev)
{
return NULL;
}
+
+static inline struct backlight_device *devm_backlight_get(struct device *dev)
+{
+ return NULL;
+}
#endif
#endif
--
2.7.4
More information about the dri-devel
mailing list