hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/i2c/muxes/i2c-demux-pinctrl.c
....@@ -1,12 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Pinctrl based I2C DeMultiplexer
34 *
45 * Copyright (C) 2015-16 by Wolfram Sang, Sang Engineering <wsa@sang-engineering.com>
56 * Copyright (C) 2015-16 by Renesas Electronics Corporation
6
- *
7
- * This program is free software; you can redistribute it and/or modify it
8
- * under the terms of the GNU General Public License as published by the
9
- * Free Software Foundation; version 2 of the License.
107 *
118 * See the bindings doc for DTS setup and the sysfs doc for usage information.
129 * (look for filenames containing 'i2c-demux-pinctrl' in Documentation/)
....@@ -99,6 +96,8 @@
9996
10097 /* Now fill out current adapter structure. cur_chan must be up to date */
10198 priv->algo.master_xfer = i2c_demux_master_xfer;
99
+ if (adap->algo->master_xfer_atomic)
100
+ priv->algo.master_xfer_atomic = i2c_demux_master_xfer;
102101 priv->algo.functionality = i2c_demux_functionality;
103102
104103 snprintf(priv->cur_adap.name, sizeof(priv->cur_adap.name),
....@@ -219,8 +218,8 @@
219218 return -EINVAL;
220219 }
221220
222
- priv = devm_kzalloc(&pdev->dev, sizeof(*priv)
223
- + num_chan * sizeof(struct i2c_demux_pinctrl_chan), GFP_KERNEL);
221
+ priv = devm_kzalloc(&pdev->dev, struct_size(priv, chan, num_chan),
222
+ GFP_KERNEL);
224223
225224 props = devm_kcalloc(&pdev->dev, num_chan, sizeof(*props), GFP_KERNEL);
226225
....@@ -244,6 +243,10 @@
244243
245244 props[i].name = devm_kstrdup(&pdev->dev, "status", GFP_KERNEL);
246245 props[i].value = devm_kstrdup(&pdev->dev, "ok", GFP_KERNEL);
246
+ if (!props[i].name || !props[i].value) {
247
+ err = -ENOMEM;
248
+ goto err_rollback;
249
+ }
247250 props[i].length = 3;
248251
249252 of_changeset_init(&priv->chan[i].chgset);
....@@ -262,7 +265,7 @@
262265
263266 err = device_create_file(&pdev->dev, &dev_attr_available_masters);
264267 if (err)
265
- goto err_rollback;
268
+ goto err_rollback_activation;
266269
267270 err = device_create_file(&pdev->dev, &dev_attr_current_master);
268271 if (err)
....@@ -272,8 +275,9 @@
272275
273276 err_rollback_available:
274277 device_remove_file(&pdev->dev, &dev_attr_available_masters);
275
-err_rollback:
278
+err_rollback_activation:
276279 i2c_demux_deactivate_master(priv);
280
+err_rollback:
277281 for (j = 0; j < i; j++) {
278282 of_node_put(priv->chan[j].parent_np);
279283 of_changeset_destroy(&priv->chan[j].chgset);