* [PATCH V3 1/2] i2c: core: add devm apis for i2c_new_dummy()
@ 2016-06-17 13:42 Laxman Dewangan
2016-06-17 13:42 ` [PATCH V3 2/2] i2c: Add devm_i2c_new_dummy() in managed list Laxman Dewangan
2016-06-17 15:10 ` [PATCH V3 1/2] i2c: core: add devm apis for i2c_new_dummy() kbuild test robot
0 siblings, 2 replies; 3+ messages in thread
From: Laxman Dewangan @ 2016-06-17 13:42 UTC (permalink / raw)
To: corbet, wsa; +Cc: linux-doc, linux-kernel, linux-i2c, Laxman Dewangan
Add resource managed version of i2c_new_dummy().
This helps in:
1. reducing the code size in error path to explicitly unregister
the new dummy client.
2. Sometime, need of the remove callback on client driver to just
unregister the new i2c dummy client.
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
---
Changes from V1:
- Got review comment on similar change for pinctrl and taken care of
the same on this patch as V1 has similar issue.
- Add the new devm_ APIs in the Documentation/driver-model/devres.txt
- Will push the change for using this new APIs later once this is
applied as most of consumer for these APIs are in other subsystem like
MFD/RTC.
Changes from V2:
- Drop devm_i2c_unregister_device() as it is not used in general.
---
drivers/i2c/i2c-core.c | 41 +++++++++++++++++++++++++++++++++++++++++
include/linux/i2c.h | 4 ++++
2 files changed, 45 insertions(+)
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 952d2f0..dc30b9b 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1145,6 +1145,47 @@ struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
}
EXPORT_SYMBOL_GPL(i2c_new_dummy);
+static void devm_i2c_dummy_release(struct device *dev, void *res)
+{
+ i2c_unregister_device(*(struct i2c_client **)res);
+}
+
+/**
+ * devm_i2c_new_dummy - Resource managed version of i2c_new_dummy().
+ * @dev: Device handle for which this resouce belongs to.
+ * @adapter: the adapter managing the device
+ * @address: seven bit address to be used
+ * Context: can sleep
+
+ * Please refer the details of i2c_new_dummy() for more information.
+ *
+ * This returns the new i2c client on success; or NULL to indicate an error.
+ * The new i2c_client will be automatically released when the device is unbound.
+ */
+struct i2c_client *devm_i2c_new_dummy(struct device *dev,
+ struct i2c_adapter *adapter,
+ u16 address)
+{
+ struct i2c_client **ptr, *i2c_dummy;
+
+ ptr = devres_alloc(devm_i2c_dummy_release, sizeof(*ptr),
+ GFP_KERNEL);
+ if (!ptr)
+ return NULL;
+
+ i2c_dummy = i2c_new_dummy(adapter, address);
+ if (!i2c_dummy) {
+ devres_free(ptr);
+ return NULL;
+ }
+
+ *ptr = i2c_dummy;
+ devres_add(dev, ptr);
+
+ return i2c_dummy;
+}
+EXPORT_SYMBOL_GPL(devm_i2c_new_dummy);
+
/**
* i2c_new_secondary_device - Helper to get the instantiated secondary address
* and create the associated device
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 6df7bad..257b239 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -355,6 +355,10 @@ i2c_new_secondary_device(struct i2c_client *client,
u16 default_addr);
extern void i2c_unregister_device(struct i2c_client *);
+
+extern struct i2c_client *
+devm_i2c_new_dummy(struct device *dev, struct i2c_adapter *adap, u16 address);
+
#endif /* I2C */
/* Mainboard arch_initcall() code should register all its I2C devices.
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH V3 2/2] i2c: Add devm_i2c_new_dummy() in managed list
2016-06-17 13:42 [PATCH V3 1/2] i2c: core: add devm apis for i2c_new_dummy() Laxman Dewangan
@ 2016-06-17 13:42 ` Laxman Dewangan
2016-06-17 15:10 ` [PATCH V3 1/2] i2c: core: add devm apis for i2c_new_dummy() kbuild test robot
1 sibling, 0 replies; 3+ messages in thread
From: Laxman Dewangan @ 2016-06-17 13:42 UTC (permalink / raw)
To: corbet, wsa; +Cc: linux-doc, linux-kernel, linux-i2c, Laxman Dewangan
i2c_new_dummy() gained their devm_ wrappers. Add the
devm_i2c_new_dummy() in managed APIs list.
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
---
Changes form V2:
- Drop the devm_i2c_unregister_device()
Documentation/driver-model/devres.txt | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
index f5e5223..472e446 100644
--- a/Documentation/driver-model/devres.txt
+++ b/Documentation/driver-model/devres.txt
@@ -259,6 +259,9 @@ GPIO
devm_gpio_request_one()
devm_gpio_free()
+I2C
+ devm_i2c_new_dummy()
+
IIO
devm_iio_device_alloc()
devm_iio_device_free()
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH V3 1/2] i2c: core: add devm apis for i2c_new_dummy()
2016-06-17 13:42 [PATCH V3 1/2] i2c: core: add devm apis for i2c_new_dummy() Laxman Dewangan
2016-06-17 13:42 ` [PATCH V3 2/2] i2c: Add devm_i2c_new_dummy() in managed list Laxman Dewangan
@ 2016-06-17 15:10 ` kbuild test robot
1 sibling, 0 replies; 3+ messages in thread
From: kbuild test robot @ 2016-06-17 15:10 UTC (permalink / raw)
Cc: kbuild-all, corbet, wsa, linux-doc, linux-kernel, linux-i2c,
Laxman Dewangan
[-- Attachment #1: Type: text/plain, Size: 1986 bytes --]
Hi,
[auto build test WARNING on wsa/i2c/for-next]
[also build test WARNING on next-20160617]
[cannot apply to v4.7-rc3]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Laxman-Dewangan/i2c-core-add-devm-apis-for-i2c_new_dummy/20160617-215840
base: https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux i2c/for-next
reproduce: make htmldocs
All warnings (new ones prefixed by >>):
include/linux/init.h:1: warning: no structured comments found
kernel/sched/core.c:2079: warning: No description found for parameter 'cookie'
kernel/sys.c:1: warning: no structured comments found
drivers/dma-buf/seqno-fence.c:1: warning: no structured comments found
>> drivers/i2c/i2c-core.c:1159: warning: bad line:
vim +1159 drivers/i2c/i2c-core.c
1143
1144 return i2c_new_device(adapter, &info);
1145 }
1146 EXPORT_SYMBOL_GPL(i2c_new_dummy);
1147
1148 static void devm_i2c_dummy_release(struct device *dev, void *res)
1149 {
1150 i2c_unregister_device(*(struct i2c_client **)res);
1151 }
1152
1153 /**
1154 * devm_i2c_new_dummy - Resource managed version of i2c_new_dummy().
1155 * @dev: Device handle for which this resouce belongs to.
1156 * @adapter: the adapter managing the device
1157 * @address: seven bit address to be used
1158 * Context: can sleep
> 1159
1160 * Please refer the details of i2c_new_dummy() for more information.
1161 *
1162 * This returns the new i2c client on success; or NULL to indicate an error.
1163 * The new i2c_client will be automatically released when the device is unbound.
1164 */
1165 struct i2c_client *devm_i2c_new_dummy(struct device *dev,
1166 struct i2c_adapter *adapter,
1167 u16 address)
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 6370 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-06-17 15:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-17 13:42 [PATCH V3 1/2] i2c: core: add devm apis for i2c_new_dummy() Laxman Dewangan
2016-06-17 13:42 ` [PATCH V3 2/2] i2c: Add devm_i2c_new_dummy() in managed list Laxman Dewangan
2016-06-17 15:10 ` [PATCH V3 1/2] i2c: core: add devm apis for i2c_new_dummy() kbuild test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).