summaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorHeiner Kallweit <hkallweit1@gmail.com>2019-05-16 17:13:08 -0400
committerWolfram Sang <wsa@the-dreams.de>2019-05-17 13:28:31 -0400
commit7159dbdae3c58d0200ae2550fab977a19a3c497a (patch)
treeb6ec458fe3934e5dea9bf9345e49a26bd4c7e22d /drivers/i2c
parenta6a4b66bd8f41922c543f7a820c66ed59c25995e (diff)
i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy
Currently i2c_new_device and i2c_new_dummy return just NULL in error case although they have more error details internally. Therefore move the functionality into new functions returning detailed errors and add wrappers for compatibility with the current API. This allows to use these functions with detailed error codes within the i2c core or for API extensions. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> [wsa: rename new functions and fix minor kdoc issues] Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Reviewed-by: Peter Rosin <peda@axentia.se> Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com> Reviewed-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/i2c-core-base.c74
1 files changed, 61 insertions, 13 deletions
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 9732a81bb7dd..9c38dde73366 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -714,7 +714,7 @@ static int i2c_dev_irq_from_resources(const struct resource *resources,
714} 714}
715 715
716/** 716/**
717 * i2c_new_device - instantiate an i2c device 717 * i2c_new_client_device - instantiate an i2c device
718 * @adap: the adapter managing the device 718 * @adap: the adapter managing the device
719 * @info: describes one I2C device; bus_num is ignored 719 * @info: describes one I2C device; bus_num is ignored
720 * Context: can sleep 720 * Context: can sleep
@@ -727,17 +727,17 @@ static int i2c_dev_irq_from_resources(const struct resource *resources,
727 * before any i2c_adapter could exist. 727 * before any i2c_adapter could exist.
728 * 728 *
729 * This returns the new i2c client, which may be saved for later use with 729 * This returns the new i2c client, which may be saved for later use with
730 * i2c_unregister_device(); or NULL to indicate an error. 730 * i2c_unregister_device(); or an ERR_PTR to describe the error.
731 */ 731 */
732struct i2c_client * 732static struct i2c_client *
733i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) 733i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
734{ 734{
735 struct i2c_client *client; 735 struct i2c_client *client;
736 int status; 736 int status;
737 737
738 client = kzalloc(sizeof *client, GFP_KERNEL); 738 client = kzalloc(sizeof *client, GFP_KERNEL);
739 if (!client) 739 if (!client)
740 return NULL; 740 return ERR_PTR(-ENOMEM);
741 741
742 client->adapter = adap; 742 client->adapter = adap;
743 743
@@ -803,7 +803,31 @@ out_err:
803 client->name, client->addr, status); 803 client->name, client->addr, status);
804out_err_silent: 804out_err_silent:
805 kfree(client); 805 kfree(client);
806 return NULL; 806 return ERR_PTR(status);
807}
808EXPORT_SYMBOL_GPL(i2c_new_client_device);
809
810/**
811 * i2c_new_device - instantiate an i2c device
812 * @adap: the adapter managing the device
813 * @info: describes one I2C device; bus_num is ignored
814 * Context: can sleep
815 *
816 * This deprecated function has the same functionality as
817 * @i2c_new_client_device, it just returns NULL instead of an ERR_PTR in case of
818 * an error for compatibility with current I2C API. It will be removed once all
819 * users are converted.
820 *
821 * This returns the new i2c client, which may be saved for later use with
822 * i2c_unregister_device(); or NULL to indicate an error.
823 */
824struct i2c_client *
825i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
826{
827 struct i2c_client *ret;
828
829 ret = i2c_new_client_device(adap, info);
830 return IS_ERR(ret) ? NULL : ret;
807} 831}
808EXPORT_SYMBOL_GPL(i2c_new_device); 832EXPORT_SYMBOL_GPL(i2c_new_device);
809 833
@@ -854,7 +878,7 @@ static struct i2c_driver dummy_driver = {
854}; 878};
855 879
856/** 880/**
857 * i2c_new_dummy - return a new i2c device bound to a dummy driver 881 * i2c_new_dummy_device - return a new i2c device bound to a dummy driver
858 * @adapter: the adapter managing the device 882 * @adapter: the adapter managing the device
859 * @address: seven bit address to be used 883 * @address: seven bit address to be used
860 * Context: can sleep 884 * Context: can sleep
@@ -869,15 +893,39 @@ static struct i2c_driver dummy_driver = {
869 * different driver. 893 * different driver.
870 * 894 *
871 * This returns the new i2c client, which should be saved for later use with 895 * This returns the new i2c client, which should be saved for later use with
872 * i2c_unregister_device(); or NULL to indicate an error. 896 * i2c_unregister_device(); or an ERR_PTR to describe the error.
873 */ 897 */
874struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address) 898static struct i2c_client *
899i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address)
875{ 900{
876 struct i2c_board_info info = { 901 struct i2c_board_info info = {
877 I2C_BOARD_INFO("dummy", address), 902 I2C_BOARD_INFO("dummy", address),
878 }; 903 };
879 904
880 return i2c_new_device(adapter, &info); 905 return i2c_new_client_device(adapter, &info);
906}
907EXPORT_SYMBOL_GPL(i2c_new_dummy_device);
908
909/**
910 * i2c_new_dummy - return a new i2c device bound to a dummy driver
911 * @adapter: the adapter managing the device
912 * @address: seven bit address to be used
913 * Context: can sleep
914 *
915 * This deprecated function has the same functionality as @i2c_new_dummy_device,
916 * it just returns NULL instead of an ERR_PTR in case of an error for
917 * compatibility with current I2C API. It will be removed once all users are
918 * converted.
919 *
920 * This returns the new i2c client, which should be saved for later use with
921 * i2c_unregister_device(); or NULL to indicate an error.
922 */
923struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
924{
925 struct i2c_client *ret;
926
927 ret = i2c_new_dummy_device(adapter, address);
928 return IS_ERR(ret) ? NULL : ret;
881} 929}
882EXPORT_SYMBOL_GPL(i2c_new_dummy); 930EXPORT_SYMBOL_GPL(i2c_new_dummy);
883 931
@@ -1000,9 +1048,9 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
1000 info.flags |= I2C_CLIENT_SLAVE; 1048 info.flags |= I2C_CLIENT_SLAVE;
1001 } 1049 }
1002 1050
1003 client = i2c_new_device(adap, &info); 1051 client = i2c_new_client_device(adap, &info);
1004 if (!client) 1052 if (IS_ERR(client))
1005 return -EINVAL; 1053 return PTR_ERR(client);
1006 1054
1007 /* Keep track of the added device */ 1055 /* Keep track of the added device */
1008 mutex_lock(&adap->userspace_clients_lock); 1056 mutex_lock(&adap->userspace_clients_lock);