hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/hid/hid-picolcd_core.c
....@@ -1,20 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /***************************************************************************
23 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
34 * *
45 * Based on Logitech G13 driver (v0.4) *
56 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
67 * *
7
- * This program is free software: you can redistribute it and/or modify *
8
- * it under the terms of the GNU General Public License as published by *
9
- * the Free Software Foundation, version 2 of the License. *
10
- * *
11
- * This driver is distributed in the hope that it will be useful, but *
12
- * WITHOUT ANY WARRANTY; without even the implied warranty of *
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14
- * General Public License for more details. *
15
- * *
16
- * You should have received a copy of the GNU General Public License *
17
- * along with this software. If not see <http://www.gnu.org/licenses/>. *
188 ***************************************************************************/
199
2010 #include <linux/hid.h>
....@@ -28,6 +18,7 @@
2818 #include <linux/completion.h>
2919 #include <linux/uaccess.h>
3020 #include <linux/module.h>
21
+#include <linux/string.h>
3122
3223 #include "hid-picolcd.h"
3324
....@@ -275,27 +266,20 @@
275266 {
276267 struct picolcd_data *data = dev_get_drvdata(dev);
277268 struct hid_report *report = NULL;
278
- size_t cnt = count;
279269 int timeout = data->opmode_delay;
280270 unsigned long flags;
281271
282
- if (cnt >= 3 && strncmp("lcd", buf, 3) == 0) {
272
+ if (sysfs_streq(buf, "lcd")) {
283273 if (data->status & PICOLCD_BOOTLOADER)
284274 report = picolcd_out_report(REPORT_EXIT_FLASHER, data->hdev);
285
- buf += 3;
286
- cnt -= 3;
287
- } else if (cnt >= 10 && strncmp("bootloader", buf, 10) == 0) {
275
+ } else if (sysfs_streq(buf, "bootloader")) {
288276 if (!(data->status & PICOLCD_BOOTLOADER))
289277 report = picolcd_out_report(REPORT_EXIT_KEYBOARD, data->hdev);
290
- buf += 10;
291
- cnt -= 10;
292
- }
293
- if (!report || report->maxfield != 1)
278
+ } else {
294279 return -EINVAL;
280
+ }
295281
296
- while (cnt > 0 && (buf[cnt-1] == '\n' || buf[cnt-1] == '\r'))
297
- cnt--;
298
- if (cnt != 0)
282
+ if (!report || report->maxfield != 1)
299283 return -EINVAL;
300284
301285 spin_lock_irqsave(&data->lock, flags);
....@@ -550,8 +534,7 @@
550534 data = kzalloc(sizeof(struct picolcd_data), GFP_KERNEL);
551535 if (data == NULL) {
552536 hid_err(hdev, "can't allocate space for Minibox PicoLCD device data\n");
553
- error = -ENOMEM;
554
- goto err_no_cleanup;
537
+ return -ENOMEM;
555538 }
556539
557540 spin_lock_init(&data->lock);
....@@ -613,9 +596,6 @@
613596 hid_hw_stop(hdev);
614597 err_cleanup_data:
615598 kfree(data);
616
-err_no_cleanup:
617
- hid_set_drvdata(hdev, NULL);
618
-
619599 return error;
620600 }
621601
....@@ -651,7 +631,6 @@
651631 picolcd_exit_cir(data);
652632 picolcd_exit_keys(data);
653633
654
- hid_set_drvdata(hdev, NULL);
655634 mutex_destroy(&data->mutex);
656635 /* Finally, clean up the picolcd data itself */
657636 kfree(data);