26
26
#include <drm/drm_edid.h>
27
27
#include <drm/drm_encoder.h>
28
28
#include <drm/drm_file.h>
29
+ #include <drm/drm_managed.h>
29
30
#include <drm/drm_panel.h>
30
31
#include <drm/drm_print.h>
31
32
#include <drm/drm_privacy_screen_consumer.h>
@@ -340,6 +341,10 @@ static int __drm_connector_init(struct drm_device *dev,
340
341
* should call drm_connector_cleanup() and free the connector structure.
341
342
* The connector structure should not be allocated with devm_kzalloc().
342
343
*
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
+ *
343
348
* Returns:
344
349
* Zero on success, error code on failure.
345
350
*/
@@ -372,6 +377,10 @@ EXPORT_SYMBOL(drm_connector_init);
372
377
*
373
378
* Ensures that the ddc field of the connector is correctly set.
374
379
*
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
+ *
375
384
* Returns:
376
385
* Zero on success, error code on failure.
377
386
*/
@@ -388,6 +397,57 @@ int drm_connector_init_with_ddc(struct drm_device *dev,
388
397
}
389
398
EXPORT_SYMBOL (drm_connector_init_with_ddc );
390
399
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
+
391
451
/**
392
452
* drm_connector_attach_edid_property - attach edid property.
393
453
* @connector: the connector
0 commit comments