mtd: fix build with GCC 14
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 815-v6.7-5-leds-turris-omnia-Fix-brightness-setting-and-trigger.patch
1 From ffec49d391c5f0195360912b216aa24dbc9b53c8 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= <kabel@kernel.org>
3 Date: Mon, 16 Oct 2023 16:15:38 +0200
4 Subject: [PATCH] leds: turris-omnia: Fix brightness setting and trigger
5 activating
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 I have improperly refactored commits
11 4d5ed2621c24 ("leds: turris-omnia: Make set_brightness() more efficient")
12 and
13 aaf38273cf76 ("leds: turris-omnia: Support HW controlled mode via private trigger")
14 after Lee requested a change in API semantics of the new functions I
15 introduced in commit
16 28350bc0ac77 ("leds: turris-omnia: Do not use SMBUS calls").
17
18 Before the change, the function omnia_cmd_write_u8() returned 0 on
19 success, and afterwards it returned a positive value (number of bytes
20 written). The latter version was applied, but the following commits did
21 not properly account for this change.
22
23 This results in non-functional LED's .brightness_set_blocking() and
24 trigger's .activate() methods.
25
26 The main reasoning behind the semantics change was that read/write
27 methods should return the number of read/written bytes on success.
28 It was pointed to me [1] that this is not always true (for example the
29 regmap API does not do so), and since the driver never uses this number
30 of read/written bytes information, I decided to fix this issue by
31 changing the functions to the original semantics (return 0 on success).
32
33 [1] https://lore.kernel.org/linux-gpio/ZQnn+Gi0xVlsGCYA@smile.fi.intel.com/
34
35 Fixes: 28350bc0ac77 ("leds: turris-omnia: Do not use SMBUS calls")
36 Signed-off-by: Marek BehĂșn <kabel@kernel.org>
37 ---
38 drivers/leds/leds-turris-omnia.c | 37 +++++++++++++++++---------------
39 1 file changed, 20 insertions(+), 17 deletions(-)
40
41 --- a/drivers/leds/leds-turris-omnia.c
42 +++ b/drivers/leds/leds-turris-omnia.c
43 @@ -60,8 +60,11 @@ struct omnia_leds {
44 static int omnia_cmd_write_u8(const struct i2c_client *client, u8 cmd, u8 val)
45 {
46 u8 buf[2] = { cmd, val };
47 + int ret;
48 +
49 + ret = i2c_master_send(client, buf, sizeof(buf));
50
51 - return i2c_master_send(client, buf, sizeof(buf));
52 + return ret < 0 ? ret : 0;
53 }
54
55 static int omnia_cmd_read_raw(struct i2c_adapter *adapter, u8 addr, u8 cmd,
56 @@ -81,7 +84,7 @@ static int omnia_cmd_read_raw(struct i2c
57
58 ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
59 if (likely(ret == ARRAY_SIZE(msgs)))
60 - return len;
61 + return 0;
62 else if (ret < 0)
63 return ret;
64 else
65 @@ -91,11 +94,11 @@ static int omnia_cmd_read_raw(struct i2c
66 static int omnia_cmd_read_u8(const struct i2c_client *client, u8 cmd)
67 {
68 u8 reply;
69 - int ret;
70 + int err;
71
72 - ret = omnia_cmd_read_raw(client->adapter, client->addr, cmd, &reply, 1);
73 - if (ret < 0)
74 - return ret;
75 + err = omnia_cmd_read_raw(client->adapter, client->addr, cmd, &reply, 1);
76 + if (err)
77 + return err;
78
79 return reply;
80 }
81 @@ -236,7 +239,7 @@ static void omnia_hwtrig_deactivate(stru
82
83 mutex_unlock(&leds->lock);
84
85 - if (err < 0)
86 + if (err)
87 dev_err(cdev->dev, "Cannot put LED to software mode: %i\n",
88 err);
89 }
90 @@ -302,7 +305,7 @@ static int omnia_led_register(struct i2c
91 ret = omnia_cmd_write_u8(client, CMD_LED_MODE,
92 CMD_LED_MODE_LED(led->reg) |
93 CMD_LED_MODE_USER);
94 - if (ret < 0) {
95 + if (ret) {
96 dev_err(dev, "Cannot set LED %pOF to software mode: %i\n", np,
97 ret);
98 return ret;
99 @@ -311,7 +314,7 @@ static int omnia_led_register(struct i2c
100 /* disable the LED */
101 ret = omnia_cmd_write_u8(client, CMD_LED_STATE,
102 CMD_LED_STATE_LED(led->reg));
103 - if (ret < 0) {
104 + if (ret) {
105 dev_err(dev, "Cannot set LED %pOF brightness: %i\n", np, ret);
106 return ret;
107 }
108 @@ -364,7 +367,7 @@ static ssize_t brightness_store(struct d
109 {
110 struct i2c_client *client = to_i2c_client(dev);
111 unsigned long brightness;
112 - int ret;
113 + int err;
114
115 if (kstrtoul(buf, 10, &brightness))
116 return -EINVAL;
117 @@ -372,9 +375,9 @@ static ssize_t brightness_store(struct d
118 if (brightness > 100)
119 return -EINVAL;
120
121 - ret = omnia_cmd_write_u8(client, CMD_LED_SET_BRIGHTNESS, brightness);
122 + err = omnia_cmd_write_u8(client, CMD_LED_SET_BRIGHTNESS, brightness);
123
124 - return ret < 0 ? ret : count;
125 + return err ?: count;
126 }
127 static DEVICE_ATTR_RW(brightness);
128
129 @@ -403,7 +406,7 @@ static ssize_t gamma_correction_store(st
130 struct i2c_client *client = to_i2c_client(dev);
131 struct omnia_leds *leds = i2c_get_clientdata(client);
132 bool val;
133 - int ret;
134 + int err;
135
136 if (!leds->has_gamma_correction)
137 return -EOPNOTSUPP;
138 @@ -411,9 +414,9 @@ static ssize_t gamma_correction_store(st
139 if (kstrtobool(buf, &val) < 0)
140 return -EINVAL;
141
142 - ret = omnia_cmd_write_u8(client, CMD_SET_GAMMA_CORRECTION, val);
143 + err = omnia_cmd_write_u8(client, CMD_SET_GAMMA_CORRECTION, val);
144
145 - return ret < 0 ? ret : count;
146 + return err ?: count;
147 }
148 static DEVICE_ATTR_RW(gamma_correction);
149
150 @@ -431,7 +434,7 @@ static int omnia_mcu_get_features(const
151
152 err = omnia_cmd_read_raw(client->adapter, OMNIA_MCU_I2C_ADDR,
153 CMD_GET_STATUS_WORD, &reply, sizeof(reply));
154 - if (err < 0)
155 + if (err)
156 return err;
157
158 /* Check whether MCU firmware supports the CMD_GET_FEAUTRES command */
159 @@ -440,7 +443,7 @@ static int omnia_mcu_get_features(const
160
161 err = omnia_cmd_read_raw(client->adapter, OMNIA_MCU_I2C_ADDR,
162 CMD_GET_FEATURES, &reply, sizeof(reply));
163 - if (err < 0)
164 + if (err)
165 return err;
166
167 return le16_to_cpu(reply);