Skip to content

Commit 4c49d90

Browse files
Bartosz GolaszewskiJiri Kosina
authored andcommitted
HID: cp2112: use lock guards
Simplify the code by using the lock guards from linux/cleanup.h throughout the driver. Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jiri Kosina <jkosina@suse.com>
1 parent 837b05f commit 4c49d90

File tree

1 file changed

+11
-27
lines changed

1 file changed

+11
-27
lines changed

drivers/hid/hid-cp2112.c

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static int cp2112_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
187187
u8 *buf = dev->in_out_buffer;
188188
int ret;
189189

190-
mutex_lock(&dev->lock);
190+
guard(mutex)(&dev->lock);
191191

192192
ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf,
193193
CP2112_GPIO_CONFIG_LENGTH, HID_FEATURE_REPORT,
@@ -196,7 +196,7 @@ static int cp2112_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
196196
hid_err(hdev, "error requesting GPIO config: %d\n", ret);
197197
if (ret >= 0)
198198
ret = -EIO;
199-
goto exit;
199+
return ret;
200200
}
201201

202202
buf[1] &= ~BIT(offset);
@@ -209,14 +209,10 @@ static int cp2112_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
209209
hid_err(hdev, "error setting GPIO config: %d\n", ret);
210210
if (ret >= 0)
211211
ret = -EIO;
212-
goto exit;
212+
return ret;
213213
}
214214

215-
ret = 0;
216-
217-
exit:
218-
mutex_unlock(&dev->lock);
219-
return ret;
215+
return 0;
220216
}
221217

222218
static void cp2112_gpio_set_unlocked(struct cp2112_device *dev,
@@ -244,7 +240,7 @@ static void cp2112_gpio_set(struct gpio_chip *chip, unsigned int offset,
244240

245241
guard(mutex)(&dev->lock);
246242

247-
return cp2112_gpio_set_unlocked(dev, offset, value);
243+
cp2112_gpio_set_unlocked(dev, offset, value);
248244
}
249245

250246
static int cp2112_gpio_get_all(struct gpio_chip *chip)
@@ -254,23 +250,17 @@ static int cp2112_gpio_get_all(struct gpio_chip *chip)
254250
u8 *buf = dev->in_out_buffer;
255251
int ret;
256252

257-
mutex_lock(&dev->lock);
253+
guard(mutex)(&dev->lock);
258254

259255
ret = hid_hw_raw_request(hdev, CP2112_GPIO_GET, buf,
260256
CP2112_GPIO_GET_LENGTH, HID_FEATURE_REPORT,
261257
HID_REQ_GET_REPORT);
262258
if (ret != CP2112_GPIO_GET_LENGTH) {
263259
hid_err(hdev, "error requesting GPIO values: %d\n", ret);
264-
ret = ret < 0 ? ret : -EIO;
265-
goto exit;
260+
return ret < 0 ? ret : -EIO;
266261
}
267262

268-
ret = buf[1];
269-
270-
exit:
271-
mutex_unlock(&dev->lock);
272-
273-
return ret;
263+
return buf[1];
274264
}
275265

276266
static int cp2112_gpio_get(struct gpio_chip *chip, unsigned int offset)
@@ -292,14 +282,14 @@ static int cp2112_gpio_direction_output(struct gpio_chip *chip,
292282
u8 *buf = dev->in_out_buffer;
293283
int ret;
294284

295-
mutex_lock(&dev->lock);
285+
guard(mutex)(&dev->lock);
296286

297287
ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf,
298288
CP2112_GPIO_CONFIG_LENGTH, HID_FEATURE_REPORT,
299289
HID_REQ_GET_REPORT);
300290
if (ret != CP2112_GPIO_CONFIG_LENGTH) {
301291
hid_err(hdev, "error requesting GPIO config: %d\n", ret);
302-
goto fail;
292+
return ret < 0 ? ret : -EIO;
303293
}
304294

305295
buf[1] |= 1 << offset;
@@ -310,7 +300,7 @@ static int cp2112_gpio_direction_output(struct gpio_chip *chip,
310300
HID_REQ_SET_REPORT);
311301
if (ret < 0) {
312302
hid_err(hdev, "error setting GPIO config: %d\n", ret);
313-
goto fail;
303+
return ret;
314304
}
315305

316306
/*
@@ -319,13 +309,7 @@ static int cp2112_gpio_direction_output(struct gpio_chip *chip,
319309
*/
320310
cp2112_gpio_set_unlocked(dev, offset, value);
321311

322-
mutex_unlock(&dev->lock);
323-
324312
return 0;
325-
326-
fail:
327-
mutex_unlock(&dev->lock);
328-
return ret < 0 ? ret : -EIO;
329313
}
330314

331315
static int cp2112_hid_get(struct hid_device *hdev, unsigned char report_number,

0 commit comments

Comments
 (0)