diff mbox series

[v3,2/2] input: adp5589: Add basic devicetree support

Message ID 20200205142218.15973-2-alexandru.ardelean@analog.com (mailing list archive)
State New, archived
Headers show
Series [v3,1/2,RESEND] input: adp5589: Add default platform data | expand

Commit Message

Alexandru Ardelean Feb. 5, 2020, 2:22 p.m. UTC
From: Lars-Peter Clausen <lars@metafoo.de>

Add very basic devicetree suppport to the adp5589 allowing the device to be
registered from devicetree.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/input/keyboard/adp5589-keys.c | 33 ++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

Comments

Dan Carpenter Feb. 13, 2020, 6:52 a.m. UTC | #1
Hi Alexandru,

url:    https://urldefense.com/v3/__https://github.com/0day-ci/linux/commits/Alexandru-Ardelean/input-adp5589-Add-default-platform-data/20200206-073944__;!!GqivPVa7Brio!MY2_vTOsanTGzkj1sG9gmxs-c72f_T0MK8vYxgXFLKcqgchKaYGVs4ZRunDQ5YstlQ$ 
base:   https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git__;!!GqivPVa7Brio!MY2_vTOsanTGzkj1sG9gmxs-c72f_T0MK8vYxgXFLKcqgchKaYGVs4ZRunDPI_jD3g$  next

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
drivers/input/keyboard/adp5589-keys.c:1053 adp5589_probe() warn: possible memory leak of 'kpad'

Old smatch warnings:
drivers/input/keyboard/adp5589-keys.c:913 adp5589_keypad_add() error: we previously assumed 'pdata->gpimap' could be null (see line 902)

# https://urldefense.com/v3/__https://github.com/0day-ci/linux/commit/e537dc5175805cf765da36bdd9cafe98b0a191d9__;!!GqivPVa7Brio!MY2_vTOsanTGzkj1sG9gmxs-c72f_T0MK8vYxgXFLKcqgchKaYGVs4ZRunBH8qj3xg$ 
git remote add linux-review https://urldefense.com/v3/__https://github.com/0day-ci/linux__;!!GqivPVa7Brio!MY2_vTOsanTGzkj1sG9gmxs-c72f_T0MK8vYxgXFLKcqgchKaYGVs4ZRunDP90BKkw$ 
git remote update linux-review
git checkout e537dc5175805cf765da36bdd9cafe98b0a191d9
vim +/kpad +1053 drivers/input/keyboard/adp5589-keys.c

cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1030  static int adp5589_probe(struct i2c_client *client,
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1031  			 const struct i2c_device_id *id)
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1032  {
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1033  	struct adp5589_kpad *kpad;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1034  	const struct adp5589_kpad_platform_data *pdata =
ba322093a2bfbb Lars-Peter Clausen 2020-02-05  1035  		adp5589_kpad_pdata_get(&client->dev);
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1036  	unsigned int revid;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1037  	int error, ret;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1038  
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1039  	if (!i2c_check_functionality(client->adapter,
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1040  				     I2C_FUNC_SMBUS_BYTE_DATA)) {
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1041  		dev_err(&client->dev, "SMBUS Byte Data not Supported\n");
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1042  		return -EIO;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1043  	}
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1044  
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1045  	kpad = kzalloc(sizeof(*kpad), GFP_KERNEL);
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1046  	if (!kpad)
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1047  		return -ENOMEM;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1048  
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1049  	kpad->client = client;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1050  
e537dc5175805c Lars-Peter Clausen 2020-02-05  1051  	ret = adp5589_i2c_get_driver_data(client, id);
e537dc5175805c Lars-Peter Clausen 2020-02-05  1052  	if (ret < 0)
e537dc5175805c Lars-Peter Clausen 2020-02-05 @1053  		return ret;

	error = ret;
	goto err_free_mem;

Better to just delete the "error" variable though and make everything
ret.

e537dc5175805c Lars-Peter Clausen 2020-02-05  1054  
e537dc5175805c Lars-Peter Clausen 2020-02-05  1055  	switch (ret) {
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1056  	case ADP5585_02:
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1057  		kpad->support_row5 = true;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1058  		/* fall through */
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1059  	case ADP5585_01:
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1060  		kpad->is_adp5585 = true;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1061  		kpad->var = &const_adp5585;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1062  		break;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1063  	case ADP5589:
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1064  		kpad->support_row5 = true;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1065  		kpad->var = &const_adp5589;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1066  		break;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1067  	}
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1068  
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1069  	ret = adp5589_read(client, ADP5589_5_ID);
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1070  	if (ret < 0) {
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1071  		error = ret;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1072  		goto err_free_mem;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1073  	}
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1074  
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1075  	revid = (u8) ret & ADP5589_5_DEVICE_ID_MASK;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1076  
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1077  	if (pdata->keymapsize) {
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1078  		error = adp5589_keypad_add(kpad, revid);
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1079  		if (error)
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1080  			goto err_free_mem;
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1081  	}
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1082  
9d2e173644bb5c Michael Hennerich  2011-05-19  1083  	error = adp5589_setup(kpad);
9d2e173644bb5c Michael Hennerich  2011-05-19  1084  	if (error)
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1085  		goto err_keypad_remove;
9d2e173644bb5c Michael Hennerich  2011-05-19  1086  
9d2e173644bb5c Michael Hennerich  2011-05-19  1087  	if (kpad->gpimapsize)
9d2e173644bb5c Michael Hennerich  2011-05-19  1088  		adp5589_report_switch_state(kpad);
9d2e173644bb5c Michael Hennerich  2011-05-19  1089  
9d2e173644bb5c Michael Hennerich  2011-05-19  1090  	error = adp5589_gpio_add(kpad);
9d2e173644bb5c Michael Hennerich  2011-05-19  1091  	if (error)
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1092  		goto err_keypad_remove;
9d2e173644bb5c Michael Hennerich  2011-05-19  1093  
9d2e173644bb5c Michael Hennerich  2011-05-19  1094  	i2c_set_clientdata(client, kpad);
9d2e173644bb5c Michael Hennerich  2011-05-19  1095  
9d2e173644bb5c Michael Hennerich  2011-05-19  1096  	dev_info(&client->dev, "Rev.%d keypad, irq %d\n", revid, client->irq);
9d2e173644bb5c Michael Hennerich  2011-05-19  1097  	return 0;
9d2e173644bb5c Michael Hennerich  2011-05-19  1098  
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1099  err_keypad_remove:
cb3efd5a38855e Lars-Peter Clausen 2019-10-23  1100  	adp5589_keypad_remove(kpad);
3f48e735435851 Michael Hennerich  2011-10-18  1101  err_free_mem:
9d2e173644bb5c Michael Hennerich  2011-05-19  1102  	kfree(kpad);
9d2e173644bb5c Michael Hennerich  2011-05-19  1103  
9d2e173644bb5c Michael Hennerich  2011-05-19  1104  	return error;
9d2e173644bb5c Michael Hennerich  2011-05-19  1105  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://urldefense.com/v3/__https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org__;!!GqivPVa7Brio!MY2_vTOsanTGzkj1sG9gmxs-c72f_T0MK8vYxgXFLKcqgchKaYGVs4ZRunCDo3i4pw$
diff mbox series

Patch

diff --git a/drivers/input/keyboard/adp5589-keys.c b/drivers/input/keyboard/adp5589-keys.c
index c6a801bcdf90..56f4ff7fa9c3 100644
--- a/drivers/input/keyboard/adp5589-keys.c
+++ b/drivers/input/keyboard/adp5589-keys.c
@@ -1008,6 +1008,25 @@  static void adp5589_keypad_remove(struct adp5589_kpad *kpad)
 	}
 }
 
+static int adp5589_i2c_get_driver_data(struct i2c_client *i2c,
+				       const struct i2c_device_id *id)
+{
+	const struct of_device_id *match;
+
+	if (id)
+		return id->driver_data;
+
+	if (!IS_ENABLED(CONFIG_OF) || !i2c->dev.of_node)
+		return -ENODEV;
+
+	match = of_match_node(i2c->dev.driver->of_match_table,
+			      i2c->dev.of_node);
+	if (match)
+		return (uintptr_t)match->data;
+
+	return -ENODEV;
+}
+
 static int adp5589_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
@@ -1029,7 +1048,11 @@  static int adp5589_probe(struct i2c_client *client,
 
 	kpad->client = client;
 
-	switch (id->driver_data) {
+	ret = adp5589_i2c_get_driver_data(client, id);
+	if (ret < 0)
+		return ret;
+
+	switch (ret) {
 	case ADP5585_02:
 		kpad->support_row5 = true;
 		/* fall through */
@@ -1129,6 +1152,13 @@  static int adp5589_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(adp5589_dev_pm_ops, adp5589_suspend, adp5589_resume);
 
+static const struct of_device_id adp5589_of_match[] = {
+	{ .compatible = "adi,adp5585", .data = (void *)ADP5585_01 },
+	{ .compatible = "adi,adp5585-02", .data = (void *)ADP5585_02 },
+	{ .compatible = "adi,adp5589", .data = (void *)ADP5589 },
+	{}
+};
+
 static const struct i2c_device_id adp5589_id[] = {
 	{"adp5589-keys", ADP5589},
 	{"adp5585-keys", ADP5585_01},
@@ -1142,6 +1172,7 @@  static struct i2c_driver adp5589_driver = {
 	.driver = {
 		.name = KBUILD_MODNAME,
 		.pm = &adp5589_dev_pm_ops,
+		.of_match_table = adp5589_of_match,
 	},
 	.probe = adp5589_probe,
 	.remove = adp5589_remove,