Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/mipi-dsi: Create devm device attachment

MIPI-DSI devices need to call mipi_dsi_attach() when their probe is done
to attach against their host.

However, at removal or when an error occurs, that attachment needs to be
undone through a call to mipi_dsi_detach().

Let's create a device-managed variant of the attachment function that
will automatically detach the device at unbind.

Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://patchwork.freedesktop.org/patch/msgid/20210910101218.1632297-5-maxime@cerno.tech

+36
+35
drivers/gpu/drm/drm_mipi_dsi.c
··· 391 391 } 392 392 EXPORT_SYMBOL(mipi_dsi_detach); 393 393 394 + static void devm_mipi_dsi_detach(void *arg) 395 + { 396 + struct mipi_dsi_device *dsi = arg; 397 + 398 + mipi_dsi_detach(dsi); 399 + } 400 + 401 + /** 402 + * devm_mipi_dsi_attach - Attach a MIPI-DSI device to its DSI Host 403 + * @dev: device to tie the MIPI-DSI device attachment lifetime to 404 + * @dsi: DSI peripheral 405 + * 406 + * This is the managed version of mipi_dsi_attach() which automatically 407 + * calls mipi_dsi_detach() when @dev is unbound. 408 + * 409 + * Returns: 410 + * 0 on success, a negative error code on failure. 411 + */ 412 + int devm_mipi_dsi_attach(struct device *dev, 413 + struct mipi_dsi_device *dsi) 414 + { 415 + int ret; 416 + 417 + ret = mipi_dsi_attach(dsi); 418 + if (ret) 419 + return ret; 420 + 421 + ret = devm_add_action_or_reset(dev, devm_mipi_dsi_detach, dsi); 422 + if (ret) 423 + return ret; 424 + 425 + return 0; 426 + } 427 + EXPORT_SYMBOL_GPL(devm_mipi_dsi_attach); 428 + 394 429 static ssize_t mipi_dsi_device_transfer(struct mipi_dsi_device *dsi, 395 430 struct mipi_dsi_msg *msg) 396 431 {
+1
include/drm/drm_mipi_dsi.h
··· 233 233 struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np); 234 234 int mipi_dsi_attach(struct mipi_dsi_device *dsi); 235 235 int mipi_dsi_detach(struct mipi_dsi_device *dsi); 236 + int devm_mipi_dsi_attach(struct device *dev, struct mipi_dsi_device *dsi); 236 237 int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi); 237 238 int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi); 238 239 int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,