Commit ec0c8d55 authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Mauro Carvalho Chehab

[media] V4L: soc_camera_platform: add helper functions to manage device instances

Add helper inline functions to correctly manage dynamic allocation and
freeing of platform devices. This avoids the ugly code to nullify
device objects.
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Acked-by: default avatarMagnus Damm <damm@opensource.se>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent e0df5417
...@@ -25,4 +25,54 @@ struct soc_camera_platform_info { ...@@ -25,4 +25,54 @@ struct soc_camera_platform_info {
int (*set_capture)(struct soc_camera_platform_info *info, int enable); int (*set_capture)(struct soc_camera_platform_info *info, int enable);
}; };
static inline void soc_camera_platform_release(struct platform_device **pdev)
{
*pdev = NULL;
}
static inline int soc_camera_platform_add(const struct soc_camera_link *icl,
struct device *dev,
struct platform_device **pdev,
struct soc_camera_link *plink,
void (*release)(struct device *dev),
int id)
{
struct soc_camera_platform_info *info = plink->priv;
int ret;
if (icl != plink)
return -ENODEV;
if (*pdev)
return -EBUSY;
*pdev = platform_device_alloc("soc_camera_platform", id);
if (!*pdev)
return -ENOMEM;
info->dev = dev;
(*pdev)->dev.platform_data = info;
(*pdev)->dev.release = release;
ret = platform_device_add(*pdev);
if (ret < 0) {
platform_device_put(*pdev);
*pdev = NULL;
info->dev = NULL;
}
return ret;
}
static inline void soc_camera_platform_del(const struct soc_camera_link *icl,
struct platform_device *pdev,
const struct soc_camera_link *plink)
{
if (icl != plink || !pdev)
return;
platform_device_unregister(pdev);
}
#endif /* __SOC_CAMERA_H__ */ #endif /* __SOC_CAMERA_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment