There is no need to allocate axes information separately from the main
joystick structure so let's fold the allocation and also drop members
(such as range, flat and fuzz) that are only used during initialization
of the device.
Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/input/joystick/adc-joystick.c | 109 ++++++++++++++------------
1 file changed, 58 insertions(+), 51 deletions(-)
diff --git a/drivers/input/joystick/adc-joystick.c b/drivers/input/joystick/adc-joystick.c
index 916e78e4dc9f..c71e582aa32d 100644
--- a/drivers/input/joystick/adc-joystick.c
+++ b/drivers/input/joystick/adc-joystick.c
@@ -15,19 +15,15 @@
struct adc_joystick_axis {
u32 code;
- s32 range[2];
- s32 fuzz;
- s32 flat;
bool inverted;
};
struct adc_joystick {
struct input_dev *input;
struct iio_cb_buffer *buffer;
- struct adc_joystick_axis *axes;
struct iio_channel *chans;
- int num_chans;
- bool polled;
+ unsigned int num_chans;
+ struct adc_joystick_axis axes[] __counted_by(num_chans);
};
static int adc_joystick_invert(struct input_dev *dev,
@@ -137,7 +133,9 @@ static int adc_joystick_set_axes(struct device *dev, struct adc_joystick *joy)
{
struct adc_joystick_axis *axes;
struct fwnode_handle *child;
- int num_axes, error, i;
+ s32 range[2], fuzz, flat;
+ unsigned int num_axes;
+ int error, i;
num_axes = device_get_child_node_count(dev);
if (!num_axes) {
@@ -151,10 +149,6 @@ static int adc_joystick_set_axes(struct device *dev, struct adc_joystick *joy)
return -EINVAL;
}
- axes = devm_kmalloc_array(dev, num_axes, sizeof(*axes), GFP_KERNEL);
- if (!axes)
- return -ENOMEM;
-
device_for_each_child_node(dev, child) {
error = fwnode_property_read_u32(child, "reg", &i);
if (error) {
@@ -176,29 +170,25 @@ static int adc_joystick_set_axes(struct device *dev, struct adc_joystick *joy)
}
error = fwnode_property_read_u32_array(child, "abs-range",
- axes[i].range, 2);
+ range, 2);
if (error) {
dev_err(dev, "abs-range invalid or missing\n");
goto err_fwnode_put;
}
- if (axes[i].range[0] > axes[i].range[1]) {
+ if (range[0] > range[1]) {
dev_dbg(dev, "abs-axis %d inverted\n", i);
axes[i].inverted = true;
- swap(axes[i].range[0], axes[i].range[1]);
+ swap(range[0], range[1]);
}
- fwnode_property_read_u32(child, "abs-fuzz", &axes[i].fuzz);
- fwnode_property_read_u32(child, "abs-flat", &axes[i].flat);
+ fwnode_property_read_u32(child, "abs-fuzz", &fuzz);
+ fwnode_property_read_u32(child, "abs-flat", &flat);
input_set_abs_params(joy->input, axes[i].code,
- axes[i].range[0], axes[i].range[1],
- axes[i].fuzz, axes[i].flat);
- input_set_capability(joy->input, EV_ABS, axes[i].code);
+ range[0], range[1], fuzz, flat);
}
- joy->axes = axes;
-
return 0;
err_fwnode_put:
@@ -206,22 +196,48 @@ static int adc_joystick_set_axes(struct device *dev, struct adc_joystick *joy)
return error;
}
+
+/*
+ * Count how many channels we got. NULL terminated.
+ * Do not check the storage size if using polling.
+ */
+static int adc_joystick_count_channels(struct device *dev,
+ const struct iio_channel *chans,
+ bool polled,
+ unsigned int *num_chans)
+{
+ int bits;
+ int i;
+
+ for (i = 0; chans[i].indio_dev; i++) {
+ if (polled)
+ continue;
+ bits = chans[i].channel->scan_type.storagebits;
+ if (!bits || bits > 16) {
+ dev_err(dev, "Unsupported channel storage size\n");
+ return -EINVAL;
+ }
+ if (bits != chans[0].channel->scan_type.storagebits) {
+ dev_err(dev, "Channels must have equal storage size\n");
+ return -EINVAL;
+ }
+ }
+
+ return i;
+}
+
static int adc_joystick_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
+ struct iio_channel *chans;
struct adc_joystick *joy;
struct input_dev *input;
+ unsigned int poll_interval = 0;
+ unsigned int num_chans;
int error;
- int bits;
- int i;
- unsigned int poll_interval;
-
- joy = devm_kzalloc(dev, sizeof(*joy), GFP_KERNEL);
- if (!joy)
- return -ENOMEM;
- joy->chans = devm_iio_channel_get_all(dev);
- if (IS_ERR(joy->chans)) {
+ chans = devm_iio_channel_get_all(dev);
+ if (IS_ERR(chans)) {
error = PTR_ERR(joy->chans);
if (error != -EPROBE_DEFER)
dev_err(dev, "Unable to get IIO channels");
@@ -236,28 +252,19 @@ static int adc_joystick_probe(struct platform_device *pdev)
} else if (poll_interval == 0) {
dev_err(dev, "Unable to get poll-interval\n");
return -EINVAL;
- } else {
- joy->polled = true;
}
- /*
- * Count how many channels we got. NULL terminated.
- * Do not check the storage size if using polling.
- */
- for (i = 0; joy->chans[i].indio_dev; i++) {
- if (joy->polled)
- continue;
- bits = joy->chans[i].channel->scan_type.storagebits;
- if (!bits || bits > 16) {
- dev_err(dev, "Unsupported channel storage size\n");
- return -EINVAL;
- }
- if (bits != joy->chans[0].channel->scan_type.storagebits) {
- dev_err(dev, "Channels must have equal storage size\n");
- return -EINVAL;
- }
- }
- joy->num_chans = i;
+ error = adc_joystick_count_channels(dev, chans, poll_interval != 0,
+ &num_chans);
+ if (error)
+ return error;
+
+ joy = devm_kzalloc(dev, struct_size(joy, axes, num_chans), GFP_KERNEL);
+ if (!joy)
+ return -ENOMEM;
+
+ joy->chans = chans;
+ joy->num_chans = num_chans;
input = devm_input_allocate_device(dev);
if (!input) {
@@ -273,7 +280,7 @@ static int adc_joystick_probe(struct platform_device *pdev)
if (error)
return error;
- if (joy->polled) {
+ if (poll_interval != 0) {
input_setup_polling(input, adc_joystick_poll);
input_set_poll_interval(input, poll_interval);
} else {
--
2.45.2.505.gda0bf45e8d-goog
--
Dmitry
Hi Dmitry,
kernel test robot noticed the following build warnings:
[auto build test WARNING on dtor-input/next]
[cannot apply to dtor-input/for-linus hid/for-next linus/master v6.10-rc3 next-20240607]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Dmitry-Torokhov/Input-adc-joystick-move-axes-data-into-the-main-structure/20240610-060124
base: https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
patch link: https://lore.kernel.org/r/ZmYlfKDm5sgB44EU%40google.com
patch subject: [PATCH] Input: adc-joystick - move axes data into the main structure
config: i386-buildonly-randconfig-006-20240610 (https://download.01.org/0day-ci/archive/20240610/[email protected]/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240610/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/input/joystick/adc-joystick.c:166:9: warning: variable 'axes' is uninitialized when used here [-Wuninitialized]
166 | &axes[i].code);
| ^~~~
drivers/input/joystick/adc-joystick.c:134:32: note: initialize the variable 'axes' to silence this warning
134 | struct adc_joystick_axis *axes;
| ^
| = NULL
>> drivers/input/joystick/adc-joystick.c:241:19: warning: variable 'joy' is uninitialized when used here [-Wuninitialized]
241 | error = PTR_ERR(joy->chans);
| ^~~
drivers/input/joystick/adc-joystick.c:233:26: note: initialize the variable 'joy' to silence this warning
233 | struct adc_joystick *joy;
| ^
| = NULL
2 warnings generated.
vim +/axes +166 drivers/input/joystick/adc-joystick.c
2c2b364fddd551 Artur Rojek 2020-09-28 131
2c2b364fddd551 Artur Rojek 2020-09-28 132 static int adc_joystick_set_axes(struct device *dev, struct adc_joystick *joy)
2c2b364fddd551 Artur Rojek 2020-09-28 133 {
2c2b364fddd551 Artur Rojek 2020-09-28 134 struct adc_joystick_axis *axes;
2c2b364fddd551 Artur Rojek 2020-09-28 135 struct fwnode_handle *child;
815b74328f141f Dmitry Torokhov 2024-06-09 136 s32 range[2], fuzz, flat;
815b74328f141f Dmitry Torokhov 2024-06-09 137 unsigned int num_axes;
815b74328f141f Dmitry Torokhov 2024-06-09 138 int error, i;
2c2b364fddd551 Artur Rojek 2020-09-28 139
2c2b364fddd551 Artur Rojek 2020-09-28 140 num_axes = device_get_child_node_count(dev);
2c2b364fddd551 Artur Rojek 2020-09-28 141 if (!num_axes) {
2c2b364fddd551 Artur Rojek 2020-09-28 142 dev_err(dev, "Unable to find child nodes\n");
2c2b364fddd551 Artur Rojek 2020-09-28 143 return -EINVAL;
2c2b364fddd551 Artur Rojek 2020-09-28 144 }
2c2b364fddd551 Artur Rojek 2020-09-28 145
2c2b364fddd551 Artur Rojek 2020-09-28 146 if (num_axes != joy->num_chans) {
2c2b364fddd551 Artur Rojek 2020-09-28 147 dev_err(dev, "Got %d child nodes for %d channels\n",
2c2b364fddd551 Artur Rojek 2020-09-28 148 num_axes, joy->num_chans);
2c2b364fddd551 Artur Rojek 2020-09-28 149 return -EINVAL;
2c2b364fddd551 Artur Rojek 2020-09-28 150 }
2c2b364fddd551 Artur Rojek 2020-09-28 151
2c2b364fddd551 Artur Rojek 2020-09-28 152 device_for_each_child_node(dev, child) {
2c2b364fddd551 Artur Rojek 2020-09-28 153 error = fwnode_property_read_u32(child, "reg", &i);
2c2b364fddd551 Artur Rojek 2020-09-28 154 if (error) {
2c2b364fddd551 Artur Rojek 2020-09-28 155 dev_err(dev, "reg invalid or missing\n");
2c2b364fddd551 Artur Rojek 2020-09-28 156 goto err_fwnode_put;
2c2b364fddd551 Artur Rojek 2020-09-28 157 }
2c2b364fddd551 Artur Rojek 2020-09-28 158
2c2b364fddd551 Artur Rojek 2020-09-28 159 if (i >= num_axes) {
2c2b364fddd551 Artur Rojek 2020-09-28 160 error = -EINVAL;
2c2b364fddd551 Artur Rojek 2020-09-28 161 dev_err(dev, "No matching axis for reg %d\n", i);
2c2b364fddd551 Artur Rojek 2020-09-28 162 goto err_fwnode_put;
2c2b364fddd551 Artur Rojek 2020-09-28 163 }
2c2b364fddd551 Artur Rojek 2020-09-28 164
2c2b364fddd551 Artur Rojek 2020-09-28 165 error = fwnode_property_read_u32(child, "linux,code",
2c2b364fddd551 Artur Rojek 2020-09-28 @166 &axes[i].code);
2c2b364fddd551 Artur Rojek 2020-09-28 167 if (error) {
2c2b364fddd551 Artur Rojek 2020-09-28 168 dev_err(dev, "linux,code invalid or missing\n");
2c2b364fddd551 Artur Rojek 2020-09-28 169 goto err_fwnode_put;
2c2b364fddd551 Artur Rojek 2020-09-28 170 }
2c2b364fddd551 Artur Rojek 2020-09-28 171
2c2b364fddd551 Artur Rojek 2020-09-28 172 error = fwnode_property_read_u32_array(child, "abs-range",
815b74328f141f Dmitry Torokhov 2024-06-09 173 range, 2);
2c2b364fddd551 Artur Rojek 2020-09-28 174 if (error) {
2c2b364fddd551 Artur Rojek 2020-09-28 175 dev_err(dev, "abs-range invalid or missing\n");
2c2b364fddd551 Artur Rojek 2020-09-28 176 goto err_fwnode_put;
2c2b364fddd551 Artur Rojek 2020-09-28 177 }
2c2b364fddd551 Artur Rojek 2020-09-28 178
815b74328f141f Dmitry Torokhov 2024-06-09 179 if (range[0] > range[1]) {
6560cfcfb46511 Chris Morgan 2024-01-19 180 dev_dbg(dev, "abs-axis %d inverted\n", i);
6560cfcfb46511 Chris Morgan 2024-01-19 181 axes[i].inverted = true;
815b74328f141f Dmitry Torokhov 2024-06-09 182 swap(range[0], range[1]);
6560cfcfb46511 Chris Morgan 2024-01-19 183 }
6560cfcfb46511 Chris Morgan 2024-01-19 184
815b74328f141f Dmitry Torokhov 2024-06-09 185 fwnode_property_read_u32(child, "abs-fuzz", &fuzz);
815b74328f141f Dmitry Torokhov 2024-06-09 186 fwnode_property_read_u32(child, "abs-flat", &flat);
2c2b364fddd551 Artur Rojek 2020-09-28 187
2c2b364fddd551 Artur Rojek 2020-09-28 188 input_set_abs_params(joy->input, axes[i].code,
815b74328f141f Dmitry Torokhov 2024-06-09 189 range[0], range[1], fuzz, flat);
2c2b364fddd551 Artur Rojek 2020-09-28 190 }
2c2b364fddd551 Artur Rojek 2020-09-28 191
2c2b364fddd551 Artur Rojek 2020-09-28 192 return 0;
2c2b364fddd551 Artur Rojek 2020-09-28 193
2c2b364fddd551 Artur Rojek 2020-09-28 194 err_fwnode_put:
2c2b364fddd551 Artur Rojek 2020-09-28 195 fwnode_handle_put(child);
2c2b364fddd551 Artur Rojek 2020-09-28 196 return error;
2c2b364fddd551 Artur Rojek 2020-09-28 197 }
2c2b364fddd551 Artur Rojek 2020-09-28 198
815b74328f141f Dmitry Torokhov 2024-06-09 199
815b74328f141f Dmitry Torokhov 2024-06-09 200 /*
815b74328f141f Dmitry Torokhov 2024-06-09 201 * Count how many channels we got. NULL terminated.
815b74328f141f Dmitry Torokhov 2024-06-09 202 * Do not check the storage size if using polling.
815b74328f141f Dmitry Torokhov 2024-06-09 203 */
815b74328f141f Dmitry Torokhov 2024-06-09 204 static int adc_joystick_count_channels(struct device *dev,
815b74328f141f Dmitry Torokhov 2024-06-09 205 const struct iio_channel *chans,
815b74328f141f Dmitry Torokhov 2024-06-09 206 bool polled,
815b74328f141f Dmitry Torokhov 2024-06-09 207 unsigned int *num_chans)
815b74328f141f Dmitry Torokhov 2024-06-09 208 {
815b74328f141f Dmitry Torokhov 2024-06-09 209 int bits;
815b74328f141f Dmitry Torokhov 2024-06-09 210 int i;
815b74328f141f Dmitry Torokhov 2024-06-09 211
815b74328f141f Dmitry Torokhov 2024-06-09 212 for (i = 0; chans[i].indio_dev; i++) {
815b74328f141f Dmitry Torokhov 2024-06-09 213 if (polled)
815b74328f141f Dmitry Torokhov 2024-06-09 214 continue;
815b74328f141f Dmitry Torokhov 2024-06-09 215 bits = chans[i].channel->scan_type.storagebits;
815b74328f141f Dmitry Torokhov 2024-06-09 216 if (!bits || bits > 16) {
815b74328f141f Dmitry Torokhov 2024-06-09 217 dev_err(dev, "Unsupported channel storage size\n");
815b74328f141f Dmitry Torokhov 2024-06-09 218 return -EINVAL;
815b74328f141f Dmitry Torokhov 2024-06-09 219 }
815b74328f141f Dmitry Torokhov 2024-06-09 220 if (bits != chans[0].channel->scan_type.storagebits) {
815b74328f141f Dmitry Torokhov 2024-06-09 221 dev_err(dev, "Channels must have equal storage size\n");
815b74328f141f Dmitry Torokhov 2024-06-09 222 return -EINVAL;
815b74328f141f Dmitry Torokhov 2024-06-09 223 }
815b74328f141f Dmitry Torokhov 2024-06-09 224 }
815b74328f141f Dmitry Torokhov 2024-06-09 225
815b74328f141f Dmitry Torokhov 2024-06-09 226 return i;
815b74328f141f Dmitry Torokhov 2024-06-09 227 }
815b74328f141f Dmitry Torokhov 2024-06-09 228
2c2b364fddd551 Artur Rojek 2020-09-28 229 static int adc_joystick_probe(struct platform_device *pdev)
2c2b364fddd551 Artur Rojek 2020-09-28 230 {
2c2b364fddd551 Artur Rojek 2020-09-28 231 struct device *dev = &pdev->dev;
815b74328f141f Dmitry Torokhov 2024-06-09 232 struct iio_channel *chans;
2c2b364fddd551 Artur Rojek 2020-09-28 233 struct adc_joystick *joy;
2c2b364fddd551 Artur Rojek 2020-09-28 234 struct input_dev *input;
815b74328f141f Dmitry Torokhov 2024-06-09 235 unsigned int poll_interval = 0;
815b74328f141f Dmitry Torokhov 2024-06-09 236 unsigned int num_chans;
2c2b364fddd551 Artur Rojek 2020-09-28 237 int error;
2c2b364fddd551 Artur Rojek 2020-09-28 238
815b74328f141f Dmitry Torokhov 2024-06-09 239 chans = devm_iio_channel_get_all(dev);
815b74328f141f Dmitry Torokhov 2024-06-09 240 if (IS_ERR(chans)) {
2c2b364fddd551 Artur Rojek 2020-09-28 @241 error = PTR_ERR(joy->chans);
2c2b364fddd551 Artur Rojek 2020-09-28 242 if (error != -EPROBE_DEFER)
2c2b364fddd551 Artur Rojek 2020-09-28 243 dev_err(dev, "Unable to get IIO channels");
2c2b364fddd551 Artur Rojek 2020-09-28 244 return error;
2c2b364fddd551 Artur Rojek 2020-09-28 245 }
2c2b364fddd551 Artur Rojek 2020-09-28 246
24c06e000e8fa2 Chris Morgan 2022-08-16 247 error = device_property_read_u32(dev, "poll-interval", &poll_interval);
24c06e000e8fa2 Chris Morgan 2022-08-16 248 if (error) {
24c06e000e8fa2 Chris Morgan 2022-08-16 249 /* -EINVAL means the property is absent. */
24c06e000e8fa2 Chris Morgan 2022-08-16 250 if (error != -EINVAL)
24c06e000e8fa2 Chris Morgan 2022-08-16 251 return error;
24c06e000e8fa2 Chris Morgan 2022-08-16 252 } else if (poll_interval == 0) {
24c06e000e8fa2 Chris Morgan 2022-08-16 253 dev_err(dev, "Unable to get poll-interval\n");
24c06e000e8fa2 Chris Morgan 2022-08-16 254 return -EINVAL;
24c06e000e8fa2 Chris Morgan 2022-08-16 255 }
24c06e000e8fa2 Chris Morgan 2022-08-16 256
815b74328f141f Dmitry Torokhov 2024-06-09 257 error = adc_joystick_count_channels(dev, chans, poll_interval != 0,
815b74328f141f Dmitry Torokhov 2024-06-09 258 &num_chans);
815b74328f141f Dmitry Torokhov 2024-06-09 259 if (error)
815b74328f141f Dmitry Torokhov 2024-06-09 260 return error;
815b74328f141f Dmitry Torokhov 2024-06-09 261
815b74328f141f Dmitry Torokhov 2024-06-09 262 joy = devm_kzalloc(dev, struct_size(joy, axes, num_chans), GFP_KERNEL);
815b74328f141f Dmitry Torokhov 2024-06-09 263 if (!joy)
815b74328f141f Dmitry Torokhov 2024-06-09 264 return -ENOMEM;
815b74328f141f Dmitry Torokhov 2024-06-09 265
815b74328f141f Dmitry Torokhov 2024-06-09 266 joy->chans = chans;
815b74328f141f Dmitry Torokhov 2024-06-09 267 joy->num_chans = num_chans;
2c2b364fddd551 Artur Rojek 2020-09-28 268
2c2b364fddd551 Artur Rojek 2020-09-28 269 input = devm_input_allocate_device(dev);
2c2b364fddd551 Artur Rojek 2020-09-28 270 if (!input) {
2c2b364fddd551 Artur Rojek 2020-09-28 271 dev_err(dev, "Unable to allocate input device\n");
2c2b364fddd551 Artur Rojek 2020-09-28 272 return -ENOMEM;
2c2b364fddd551 Artur Rojek 2020-09-28 273 }
2c2b364fddd551 Artur Rojek 2020-09-28 274
2c2b364fddd551 Artur Rojek 2020-09-28 275 joy->input = input;
2c2b364fddd551 Artur Rojek 2020-09-28 276 input->name = pdev->name;
2c2b364fddd551 Artur Rojek 2020-09-28 277 input->id.bustype = BUS_HOST;
2c2b364fddd551 Artur Rojek 2020-09-28 278
2c2b364fddd551 Artur Rojek 2020-09-28 279 error = adc_joystick_set_axes(dev, joy);
2c2b364fddd551 Artur Rojek 2020-09-28 280 if (error)
2c2b364fddd551 Artur Rojek 2020-09-28 281 return error;
2c2b364fddd551 Artur Rojek 2020-09-28 282
815b74328f141f Dmitry Torokhov 2024-06-09 283 if (poll_interval != 0) {
24c06e000e8fa2 Chris Morgan 2022-08-16 284 input_setup_polling(input, adc_joystick_poll);
24c06e000e8fa2 Chris Morgan 2022-08-16 285 input_set_poll_interval(input, poll_interval);
24c06e000e8fa2 Chris Morgan 2022-08-16 286 } else {
24c06e000e8fa2 Chris Morgan 2022-08-16 287 input->open = adc_joystick_open;
24c06e000e8fa2 Chris Morgan 2022-08-16 288 input->close = adc_joystick_close;
24c06e000e8fa2 Chris Morgan 2022-08-16 289
24c06e000e8fa2 Chris Morgan 2022-08-16 290 joy->buffer = iio_channel_get_all_cb(dev, adc_joystick_handle,
24c06e000e8fa2 Chris Morgan 2022-08-16 291 joy);
2c2b364fddd551 Artur Rojek 2020-09-28 292 if (IS_ERR(joy->buffer)) {
2c2b364fddd551 Artur Rojek 2020-09-28 293 dev_err(dev, "Unable to allocate callback buffer\n");
2c2b364fddd551 Artur Rojek 2020-09-28 294 return PTR_ERR(joy->buffer);
2c2b364fddd551 Artur Rojek 2020-09-28 295 }
2c2b364fddd551 Artur Rojek 2020-09-28 296
24c06e000e8fa2 Chris Morgan 2022-08-16 297 error = devm_add_action_or_reset(dev, adc_joystick_cleanup,
24c06e000e8fa2 Chris Morgan 2022-08-16 298 joy->buffer);
2c2b364fddd551 Artur Rojek 2020-09-28 299 if (error) {
2c2b364fddd551 Artur Rojek 2020-09-28 300 dev_err(dev, "Unable to add action\n");
2c2b364fddd551 Artur Rojek 2020-09-28 301 return error;
2c2b364fddd551 Artur Rojek 2020-09-28 302 }
24c06e000e8fa2 Chris Morgan 2022-08-16 303 }
2c2b364fddd551 Artur Rojek 2020-09-28 304
7c744d00990ea9 Dmitry Torokhov 2022-08-02 305 input_set_drvdata(input, joy);
7c744d00990ea9 Dmitry Torokhov 2022-08-02 306
7c744d00990ea9 Dmitry Torokhov 2022-08-02 307 error = input_register_device(input);
7c744d00990ea9 Dmitry Torokhov 2022-08-02 308 if (error) {
7c744d00990ea9 Dmitry Torokhov 2022-08-02 309 dev_err(dev, "Unable to register input device\n");
7c744d00990ea9 Dmitry Torokhov 2022-08-02 310 return error;
7c744d00990ea9 Dmitry Torokhov 2022-08-02 311 }
7c744d00990ea9 Dmitry Torokhov 2022-08-02 312
2c2b364fddd551 Artur Rojek 2020-09-28 313 return 0;
2c2b364fddd551 Artur Rojek 2020-09-28 314 }
2c2b364fddd551 Artur Rojek 2020-09-28 315
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Dmitry,
kernel test robot noticed the following build warnings:
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Dmitry-Torokhov/Input-adc-joystick-move-axes-data-into-the-main-structure/20240610-060124
base: https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
patch link: https://lore.kernel.org/r/ZmYlfKDm5sgB44EU%40google.com
patch subject: [PATCH] Input: adc-joystick - move axes data into the main structure
config: x86_64-randconfig-161-20240611 (https://download.01.org/0day-ci/archive/20240611/[email protected]/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/
smatch warnings:
drivers/input/joystick/adc-joystick.c:166 adc_joystick_set_axes() error: uninitialized symbol 'axes'.
drivers/input/joystick/adc-joystick.c:241 adc_joystick_probe() error: uninitialized symbol 'joy'.
drivers/input/joystick/adc-joystick.c:241 adc_joystick_probe() warn: passing zero to 'PTR_ERR'
vim +/axes +166 drivers/input/joystick/adc-joystick.c
2c2b364fddd551 Artur Rojek 2020-09-28 131
2c2b364fddd551 Artur Rojek 2020-09-28 132 static int adc_joystick_set_axes(struct device *dev, struct adc_joystick *joy)
2c2b364fddd551 Artur Rojek 2020-09-28 133 {
2c2b364fddd551 Artur Rojek 2020-09-28 134 struct adc_joystick_axis *axes;
2c2b364fddd551 Artur Rojek 2020-09-28 135 struct fwnode_handle *child;
815b74328f141f Dmitry Torokhov 2024-06-09 136 s32 range[2], fuzz, flat;
815b74328f141f Dmitry Torokhov 2024-06-09 137 unsigned int num_axes;
815b74328f141f Dmitry Torokhov 2024-06-09 138 int error, i;
2c2b364fddd551 Artur Rojek 2020-09-28 139
2c2b364fddd551 Artur Rojek 2020-09-28 140 num_axes = device_get_child_node_count(dev);
2c2b364fddd551 Artur Rojek 2020-09-28 141 if (!num_axes) {
2c2b364fddd551 Artur Rojek 2020-09-28 142 dev_err(dev, "Unable to find child nodes\n");
2c2b364fddd551 Artur Rojek 2020-09-28 143 return -EINVAL;
2c2b364fddd551 Artur Rojek 2020-09-28 144 }
2c2b364fddd551 Artur Rojek 2020-09-28 145
2c2b364fddd551 Artur Rojek 2020-09-28 146 if (num_axes != joy->num_chans) {
2c2b364fddd551 Artur Rojek 2020-09-28 147 dev_err(dev, "Got %d child nodes for %d channels\n",
2c2b364fddd551 Artur Rojek 2020-09-28 148 num_axes, joy->num_chans);
2c2b364fddd551 Artur Rojek 2020-09-28 149 return -EINVAL;
2c2b364fddd551 Artur Rojek 2020-09-28 150 }
2c2b364fddd551 Artur Rojek 2020-09-28 151
2c2b364fddd551 Artur Rojek 2020-09-28 152 device_for_each_child_node(dev, child) {
2c2b364fddd551 Artur Rojek 2020-09-28 153 error = fwnode_property_read_u32(child, "reg", &i);
2c2b364fddd551 Artur Rojek 2020-09-28 154 if (error) {
2c2b364fddd551 Artur Rojek 2020-09-28 155 dev_err(dev, "reg invalid or missing\n");
2c2b364fddd551 Artur Rojek 2020-09-28 156 goto err_fwnode_put;
2c2b364fddd551 Artur Rojek 2020-09-28 157 }
2c2b364fddd551 Artur Rojek 2020-09-28 158
2c2b364fddd551 Artur Rojek 2020-09-28 159 if (i >= num_axes) {
2c2b364fddd551 Artur Rojek 2020-09-28 160 error = -EINVAL;
2c2b364fddd551 Artur Rojek 2020-09-28 161 dev_err(dev, "No matching axis for reg %d\n", i);
2c2b364fddd551 Artur Rojek 2020-09-28 162 goto err_fwnode_put;
2c2b364fddd551 Artur Rojek 2020-09-28 163 }
2c2b364fddd551 Artur Rojek 2020-09-28 164
2c2b364fddd551 Artur Rojek 2020-09-28 165 error = fwnode_property_read_u32(child, "linux,code",
2c2b364fddd551 Artur Rojek 2020-09-28 @166 &axes[i].code);
axes is unitialized.
2c2b364fddd551 Artur Rojek 2020-09-28 167 if (error) {
2c2b364fddd551 Artur Rojek 2020-09-28 168 dev_err(dev, "linux,code invalid or missing\n");
2c2b364fddd551 Artur Rojek 2020-09-28 169 goto err_fwnode_put;
2c2b364fddd551 Artur Rojek 2020-09-28 170 }
2c2b364fddd551 Artur Rojek 2020-09-28 171
2c2b364fddd551 Artur Rojek 2020-09-28 172 error = fwnode_property_read_u32_array(child, "abs-range",
815b74328f141f Dmitry Torokhov 2024-06-09 173 range, 2);
2c2b364fddd551 Artur Rojek 2020-09-28 174 if (error) {
2c2b364fddd551 Artur Rojek 2020-09-28 175 dev_err(dev, "abs-range invalid or missing\n");
2c2b364fddd551 Artur Rojek 2020-09-28 176 goto err_fwnode_put;
2c2b364fddd551 Artur Rojek 2020-09-28 177 }
2c2b364fddd551 Artur Rojek 2020-09-28 178
815b74328f141f Dmitry Torokhov 2024-06-09 179 if (range[0] > range[1]) {
6560cfcfb46511 Chris Morgan 2024-01-19 180 dev_dbg(dev, "abs-axis %d inverted\n", i);
6560cfcfb46511 Chris Morgan 2024-01-19 181 axes[i].inverted = true;
815b74328f141f Dmitry Torokhov 2024-06-09 182 swap(range[0], range[1]);
6560cfcfb46511 Chris Morgan 2024-01-19 183 }
6560cfcfb46511 Chris Morgan 2024-01-19 184
815b74328f141f Dmitry Torokhov 2024-06-09 185 fwnode_property_read_u32(child, "abs-fuzz", &fuzz);
815b74328f141f Dmitry Torokhov 2024-06-09 186 fwnode_property_read_u32(child, "abs-flat", &flat);
2c2b364fddd551 Artur Rojek 2020-09-28 187
2c2b364fddd551 Artur Rojek 2020-09-28 188 input_set_abs_params(joy->input, axes[i].code,
815b74328f141f Dmitry Torokhov 2024-06-09 189 range[0], range[1], fuzz, flat);
2c2b364fddd551 Artur Rojek 2020-09-28 190 }
2c2b364fddd551 Artur Rojek 2020-09-28 191
2c2b364fddd551 Artur Rojek 2020-09-28 192 return 0;
2c2b364fddd551 Artur Rojek 2020-09-28 193
2c2b364fddd551 Artur Rojek 2020-09-28 194 err_fwnode_put:
2c2b364fddd551 Artur Rojek 2020-09-28 195 fwnode_handle_put(child);
2c2b364fddd551 Artur Rojek 2020-09-28 196 return error;
2c2b364fddd551 Artur Rojek 2020-09-28 197 }
2c2b364fddd551 Artur Rojek 2020-09-28 198
815b74328f141f Dmitry Torokhov 2024-06-09 199
815b74328f141f Dmitry Torokhov 2024-06-09 200 /*
815b74328f141f Dmitry Torokhov 2024-06-09 201 * Count how many channels we got. NULL terminated.
815b74328f141f Dmitry Torokhov 2024-06-09 202 * Do not check the storage size if using polling.
815b74328f141f Dmitry Torokhov 2024-06-09 203 */
815b74328f141f Dmitry Torokhov 2024-06-09 204 static int adc_joystick_count_channels(struct device *dev,
815b74328f141f Dmitry Torokhov 2024-06-09 205 const struct iio_channel *chans,
815b74328f141f Dmitry Torokhov 2024-06-09 206 bool polled,
815b74328f141f Dmitry Torokhov 2024-06-09 207 unsigned int *num_chans)
815b74328f141f Dmitry Torokhov 2024-06-09 208 {
815b74328f141f Dmitry Torokhov 2024-06-09 209 int bits;
815b74328f141f Dmitry Torokhov 2024-06-09 210 int i;
815b74328f141f Dmitry Torokhov 2024-06-09 211
815b74328f141f Dmitry Torokhov 2024-06-09 212 for (i = 0; chans[i].indio_dev; i++) {
815b74328f141f Dmitry Torokhov 2024-06-09 213 if (polled)
815b74328f141f Dmitry Torokhov 2024-06-09 214 continue;
815b74328f141f Dmitry Torokhov 2024-06-09 215 bits = chans[i].channel->scan_type.storagebits;
815b74328f141f Dmitry Torokhov 2024-06-09 216 if (!bits || bits > 16) {
815b74328f141f Dmitry Torokhov 2024-06-09 217 dev_err(dev, "Unsupported channel storage size\n");
815b74328f141f Dmitry Torokhov 2024-06-09 218 return -EINVAL;
815b74328f141f Dmitry Torokhov 2024-06-09 219 }
815b74328f141f Dmitry Torokhov 2024-06-09 220 if (bits != chans[0].channel->scan_type.storagebits) {
815b74328f141f Dmitry Torokhov 2024-06-09 221 dev_err(dev, "Channels must have equal storage size\n");
815b74328f141f Dmitry Torokhov 2024-06-09 222 return -EINVAL;
815b74328f141f Dmitry Torokhov 2024-06-09 223 }
815b74328f141f Dmitry Torokhov 2024-06-09 224 }
815b74328f141f Dmitry Torokhov 2024-06-09 225
815b74328f141f Dmitry Torokhov 2024-06-09 226 return i;
815b74328f141f Dmitry Torokhov 2024-06-09 227 }
815b74328f141f Dmitry Torokhov 2024-06-09 228
2c2b364fddd551 Artur Rojek 2020-09-28 229 static int adc_joystick_probe(struct platform_device *pdev)
2c2b364fddd551 Artur Rojek 2020-09-28 230 {
2c2b364fddd551 Artur Rojek 2020-09-28 231 struct device *dev = &pdev->dev;
815b74328f141f Dmitry Torokhov 2024-06-09 232 struct iio_channel *chans;
2c2b364fddd551 Artur Rojek 2020-09-28 233 struct adc_joystick *joy;
2c2b364fddd551 Artur Rojek 2020-09-28 234 struct input_dev *input;
815b74328f141f Dmitry Torokhov 2024-06-09 235 unsigned int poll_interval = 0;
815b74328f141f Dmitry Torokhov 2024-06-09 236 unsigned int num_chans;
2c2b364fddd551 Artur Rojek 2020-09-28 237 int error;
2c2b364fddd551 Artur Rojek 2020-09-28 238
815b74328f141f Dmitry Torokhov 2024-06-09 239 chans = devm_iio_channel_get_all(dev);
815b74328f141f Dmitry Torokhov 2024-06-09 240 if (IS_ERR(chans)) {
2c2b364fddd551 Artur Rojek 2020-09-28 @241 error = PTR_ERR(joy->chans);
s/joy->chans/chans/
2c2b364fddd551 Artur Rojek 2020-09-28 242 if (error != -EPROBE_DEFER)
2c2b364fddd551 Artur Rojek 2020-09-28 243 dev_err(dev, "Unable to get IIO channels");
2c2b364fddd551 Artur Rojek 2020-09-28 244 return error;
2c2b364fddd551 Artur Rojek 2020-09-28 245 }
2c2b364fddd551 Artur Rojek 2020-09-28 246
24c06e000e8fa2 Chris Morgan 2022-08-16 247 error = device_property_read_u32(dev, "poll-interval", &poll_interval);
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki