diff options
author | Guennadi Liakhovetski <g.liakhovetski@gmx.de> | 2011-03-23 03:14:43 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-05-20 06:26:14 -0400 |
commit | ec0c8d555a93aa7e2c5c4f11f12686e5b2245696 (patch) | |
tree | cc0d129c4efd8adaac5c29fb93c156e1dd697e90 /include | |
parent | e0df5417acf65cff05343b1fb83fb40344e155ea (diff) |
[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')
-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 { | |||
25 | int (*set_capture)(struct soc_camera_platform_info *info, int enable); | 25 | int (*set_capture)(struct soc_camera_platform_info *info, int enable); |
26 | }; | 26 | }; |
27 | 27 | ||
28 | static inline void soc_camera_platform_release(struct platform_device **pdev) | ||
29 | { | ||
30 | *pdev = NULL; | ||
31 | } | ||
32 | |||
33 | static inline int soc_camera_platform_add(const struct soc_camera_link *icl, | ||
34 | struct device *dev, | ||
35 | struct platform_device **pdev, | ||
36 | struct soc_camera_link *plink, | ||
37 | void (*release)(struct device *dev), | ||
38 | int id) | ||
39 | { | ||
40 | struct soc_camera_platform_info *info = plink->priv; | ||
41 | int ret; | ||
42 | |||
43 | if (icl != plink) | ||
44 | return -ENODEV; | ||
45 | |||
46 | if (*pdev) | ||
47 | return -EBUSY; | ||
48 | |||
49 | *pdev = platform_device_alloc("soc_camera_platform", id); | ||
50 | if (!*pdev) | ||
51 | return -ENOMEM; | ||
52 | |||
53 | info->dev = dev; | ||
54 | |||
55 | (*pdev)->dev.platform_data = info; | ||
56 | (*pdev)->dev.release = release; | ||
57 | |||
58 | ret = platform_device_add(*pdev); | ||
59 | if (ret < 0) { | ||
60 | platform_device_put(*pdev); | ||
61 | *pdev = NULL; | ||
62 | info->dev = NULL; | ||
63 | } | ||
64 | |||
65 | return ret; | ||
66 | } | ||
67 | |||
68 | static inline void soc_camera_platform_del(const struct soc_camera_link *icl, | ||
69 | struct platform_device *pdev, | ||
70 | const struct soc_camera_link *plink) | ||
71 | { | ||
72 | if (icl != plink || !pdev) | ||
73 | return; | ||
74 | |||
75 | platform_device_unregister(pdev); | ||
76 | } | ||
77 | |||
28 | #endif /* __SOC_CAMERA_H__ */ | 78 | #endif /* __SOC_CAMERA_H__ */ |