Hi Jacek, On Wed, May 20, 2015 at 04:10:08PM +0200, Jacek Anaszewski wrote: ... > +struct v4l2_flash *v4l2_flash_init( > + struct device *dev, struct device_node *of_node, > + struct led_classdev_flash *fled_cdev, const struct v4l2_flash_ops *ops, > + struct v4l2_flash_config *config) > +{ > + struct v4l2_flash *v4l2_flash; > + struct led_classdev *led_cdev = &fled_cdev->led_cdev; > + struct v4l2_subdev *sd; > + int ret; > + > + if (!fled_cdev || !ops || !config) > + return ERR_PTR(-EINVAL); > + > + v4l2_flash = devm_kzalloc(led_cdev->dev, sizeof(*v4l2_flash), > + GFP_KERNEL); > + if (!v4l2_flash) > + return ERR_PTR(-ENOMEM); > + > + sd = &v4l2_flash->sd; > + v4l2_flash->fled_cdev = fled_cdev; > + v4l2_flash->ops = ops; > + sd->dev = dev; > + sd->of_node = of_node; > + v4l2_subdev_init(sd, &v4l2_flash_subdev_ops); > + sd->internal_ops = &v4l2_flash_subdev_internal_ops; > + sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; > + strlcpy(sd->name, config->dev_name, sizeof(sd->name)); > + > + ret = media_entity_init(&sd->entity, 0, NULL, 0); > + if (ret < 0) > + return ERR_PTR(ret); > + > + sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_FLASH; > + > + ret = v4l2_flash_init_controls(v4l2_flash, config); > + if (ret < 0) > + goto err_init_controls; > + > + of_node_get(led_cdev->dev->of_node); > + > + ret = v4l2_async_register_subdev(sd); > + if (ret < 0) > + goto err_async_register_sd; > + > + return v4l2_flash; > + > +err_async_register_sd: > + of_node_put(led_cdev->dev->of_node); > + v4l2_ctrl_handler_free(sd->ctrl_handler); > +err_init_controls: > + media_entity_cleanup(&sd->entity); > + > + return ERR_PTR(ret); > +} > +EXPORT_SYMBOL_GPL(v4l2_flash_init); > + > +void v4l2_flash_release(struct v4l2_flash *v4l2_flash) > +{ > + struct v4l2_subdev *sd; > + struct led_classdev *led_cdev; > + > + if (IS_ERR(v4l2_flash)) I propose to use IS_ERR_OR_NULL() instead. Then this can be safely called without calling v4l2_flash_init() first, making error handling easier. Acked-by: Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx> > + return; > + > + sd = &v4l2_flash->sd; > + led_cdev = &v4l2_flash->fled_cdev->led_cdev; > + > + v4l2_async_unregister_subdev(sd); > + of_node_put(led_cdev->dev->of_node); > + v4l2_ctrl_handler_free(sd->ctrl_handler); > + media_entity_cleanup(&sd->entity); > +} > +EXPORT_SYMBOL_GPL(v4l2_flash_release); ... -- Kind regards, Sakari Ailus e-mail: sakari.ailus@xxxxxx XMPP: sailus@xxxxxxxxxxxxxx -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html