diff options
author | Guennadi Liakhovetski <g.liakhovetski@gmx.de> | 2011-03-23 04:14:43 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-05-20 07:26:14 -0300 |
commit | ec0c8d555a93aa7e2c5c4f11f12686e5b2245696 (patch) | |
tree | cc0d129c4efd8adaac5c29fb93c156e1dd697e90 /include/media | |
parent | e0df5417acf65cff05343b1fb83fb40344e155ea (diff) | |
download | linux-ec0c8d555a93aa7e2c5c4f11f12686e5b2245696.tar.gz linux-ec0c8d555a93aa7e2c5c4f11f12686e5b2245696.tar.bz2 linux-ec0c8d555a93aa7e2c5c4f11f12686e5b2245696.zip |
[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: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Acked-by: Magnus Damm <damm@opensource.se>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'include/media')
-rw-r--r-- | include/media/soc_camera_platform.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/include/media/soc_camera_platform.h b/include/media/soc_camera_platform.h index 0ecefe227b76..6d7a4fd00fc0 100644 --- a/include/media/soc_camera_platform.h +++ b/include/media/soc_camera_platform.h @@ -25,4 +25,54 @@ struct soc_camera_platform_info { 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__ */ |