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 registration

Devices that take their data through the MIPI-DSI bus but are controlled
through a secondary bus like I2C have to register a secondary device on
the MIPI-DSI bus through the mipi_dsi_device_register_full() function.

At removal or when an error occurs, that device needs to be removed
through a call to mipi_dsi_device_unregister().

Let's create a device-managed variant of the registration function that
will automatically unregister 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-4-maxime@cerno.tech

+49
+46
drivers/gpu/drm/drm_mipi_dsi.c
··· 246 246 } 247 247 EXPORT_SYMBOL(mipi_dsi_device_unregister); 248 248 249 + static void devm_mipi_dsi_device_unregister(void *arg) 250 + { 251 + struct mipi_dsi_device *dsi = arg; 252 + 253 + mipi_dsi_device_unregister(dsi); 254 + } 255 + 256 + /** 257 + * devm_mipi_dsi_device_register_full - create a managed MIPI DSI device 258 + * @dev: device to tie the MIPI-DSI device lifetime to 259 + * @host: DSI host to which this device is connected 260 + * @info: pointer to template containing DSI device information 261 + * 262 + * Create a MIPI DSI device by using the device information provided by 263 + * mipi_dsi_device_info template 264 + * 265 + * This is the managed version of mipi_dsi_device_register_full() which 266 + * automatically calls mipi_dsi_device_unregister() when @dev is 267 + * unbound. 268 + * 269 + * Returns: 270 + * A pointer to the newly created MIPI DSI device, or, a pointer encoded 271 + * with an error 272 + */ 273 + struct mipi_dsi_device * 274 + devm_mipi_dsi_device_register_full(struct device *dev, 275 + struct mipi_dsi_host *host, 276 + const struct mipi_dsi_device_info *info) 277 + { 278 + struct mipi_dsi_device *dsi; 279 + int ret; 280 + 281 + dsi = mipi_dsi_device_register_full(host, info); 282 + if (IS_ERR(dsi)) 283 + return dsi; 284 + 285 + ret = devm_add_action_or_reset(dev, 286 + devm_mipi_dsi_device_unregister, 287 + dsi); 288 + if (ret) 289 + return ERR_PTR(ret); 290 + 291 + return dsi; 292 + } 293 + EXPORT_SYMBOL_GPL(devm_mipi_dsi_device_register_full); 294 + 249 295 static DEFINE_MUTEX(host_lock); 250 296 static LIST_HEAD(host_list); 251 297
+3
include/drm/drm_mipi_dsi.h
··· 227 227 mipi_dsi_device_register_full(struct mipi_dsi_host *host, 228 228 const struct mipi_dsi_device_info *info); 229 229 void mipi_dsi_device_unregister(struct mipi_dsi_device *dsi); 230 + struct mipi_dsi_device * 231 + devm_mipi_dsi_device_register_full(struct device *dev, struct mipi_dsi_host *host, 232 + const struct mipi_dsi_device_info *info); 230 233 struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np); 231 234 int mipi_dsi_attach(struct mipi_dsi_device *dsi); 232 235 int mipi_dsi_detach(struct mipi_dsi_device *dsi);