Skip to content

Commit 35a3b82

Browse files
committed
drm/connector: Introduce drmm_connector_init
Unlike other DRM entities, there's no helper to create a DRM-managed initialisation of a connector. Let's create an helper to initialise a connector that would be passed as an argument, and handle the cleanup through a DRM-managed action. Acked-by: Sam Ravnborg <[email protected]> Acked-by: Thomas Zimmermann <[email protected]> Signed-off-by: Maxime Ripard <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a961b19 commit 35a3b82

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

drivers/gpu/drm/drm_connector.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <drm/drm_edid.h>
2727
#include <drm/drm_encoder.h>
2828
#include <drm/drm_file.h>
29+
#include <drm/drm_managed.h>
2930
#include <drm/drm_panel.h>
3031
#include <drm/drm_print.h>
3132
#include <drm/drm_privacy_screen_consumer.h>
@@ -340,6 +341,10 @@ static int __drm_connector_init(struct drm_device *dev,
340341
* should call drm_connector_cleanup() and free the connector structure.
341342
* The connector structure should not be allocated with devm_kzalloc().
342343
*
344+
* Note: consider using drmm_connector_init() instead of
345+
* drm_connector_init() to let the DRM managed resource infrastructure
346+
* take care of cleanup and deallocation.
347+
*
343348
* Returns:
344349
* Zero on success, error code on failure.
345350
*/
@@ -372,6 +377,10 @@ EXPORT_SYMBOL(drm_connector_init);
372377
*
373378
* Ensures that the ddc field of the connector is correctly set.
374379
*
380+
* Note: consider using drmm_connector_init() instead of
381+
* drm_connector_init_with_ddc() to let the DRM managed resource
382+
* infrastructure take care of cleanup and deallocation.
383+
*
375384
* Returns:
376385
* Zero on success, error code on failure.
377386
*/
@@ -388,6 +397,57 @@ int drm_connector_init_with_ddc(struct drm_device *dev,
388397
}
389398
EXPORT_SYMBOL(drm_connector_init_with_ddc);
390399

400+
static void drm_connector_cleanup_action(struct drm_device *dev,
401+
void *ptr)
402+
{
403+
struct drm_connector *connector = ptr;
404+
405+
drm_connector_cleanup(connector);
406+
}
407+
408+
/**
409+
* drmm_connector_init - Init a preallocated connector
410+
* @dev: DRM device
411+
* @connector: the connector to init
412+
* @funcs: callbacks for this connector
413+
* @connector_type: user visible type of the connector
414+
* @ddc: optional pointer to the associated ddc adapter
415+
*
416+
* Initialises a preallocated connector. Connectors should be
417+
* subclassed as part of driver connector objects.
418+
*
419+
* Cleanup is automatically handled with a call to
420+
* drm_connector_cleanup() in a DRM-managed action.
421+
*
422+
* The connector structure should be allocated with drmm_kzalloc().
423+
*
424+
* Returns:
425+
* Zero on success, error code on failure.
426+
*/
427+
int drmm_connector_init(struct drm_device *dev,
428+
struct drm_connector *connector,
429+
const struct drm_connector_funcs *funcs,
430+
int connector_type,
431+
struct i2c_adapter *ddc)
432+
{
433+
int ret;
434+
435+
if (drm_WARN_ON(dev, funcs && funcs->destroy))
436+
return -EINVAL;
437+
438+
ret = __drm_connector_init(dev, connector, funcs, connector_type, NULL);
439+
if (ret)
440+
return ret;
441+
442+
ret = drmm_add_action_or_reset(dev, drm_connector_cleanup_action,
443+
connector);
444+
if (ret)
445+
return ret;
446+
447+
return 0;
448+
}
449+
EXPORT_SYMBOL(drmm_connector_init);
450+
391451
/**
392452
* drm_connector_attach_edid_property - attach edid property.
393453
* @connector: the connector

include/drm/drm_connector.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,11 @@ int drm_connector_init_with_ddc(struct drm_device *dev,
16771677
const struct drm_connector_funcs *funcs,
16781678
int connector_type,
16791679
struct i2c_adapter *ddc);
1680+
int drmm_connector_init(struct drm_device *dev,
1681+
struct drm_connector *connector,
1682+
const struct drm_connector_funcs *funcs,
1683+
int connector_type,
1684+
struct i2c_adapter *ddc);
16801685
void drm_connector_attach_edid_property(struct drm_connector *connector);
16811686
int drm_connector_register(struct drm_connector *connector);
16821687
void drm_connector_unregister(struct drm_connector *connector);

0 commit comments

Comments
 (0)