.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /*************************************************************************** |
---|
2 | 3 | * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> * |
---|
3 | 4 | * * |
---|
4 | 5 | * Based on Logitech G13 driver (v0.4) * |
---|
5 | 6 | * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> * |
---|
6 | 7 | * * |
---|
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/>. * |
---|
18 | 8 | ***************************************************************************/ |
---|
19 | 9 | |
---|
20 | 10 | #include <linux/hid.h> |
---|
.. | .. |
---|
28 | 18 | #include <linux/completion.h> |
---|
29 | 19 | #include <linux/uaccess.h> |
---|
30 | 20 | #include <linux/module.h> |
---|
| 21 | +#include <linux/string.h> |
---|
31 | 22 | |
---|
32 | 23 | #include "hid-picolcd.h" |
---|
33 | 24 | |
---|
.. | .. |
---|
275 | 266 | { |
---|
276 | 267 | struct picolcd_data *data = dev_get_drvdata(dev); |
---|
277 | 268 | struct hid_report *report = NULL; |
---|
278 | | - size_t cnt = count; |
---|
279 | 269 | int timeout = data->opmode_delay; |
---|
280 | 270 | unsigned long flags; |
---|
281 | 271 | |
---|
282 | | - if (cnt >= 3 && strncmp("lcd", buf, 3) == 0) { |
---|
| 272 | + if (sysfs_streq(buf, "lcd")) { |
---|
283 | 273 | if (data->status & PICOLCD_BOOTLOADER) |
---|
284 | 274 | 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")) { |
---|
288 | 276 | if (!(data->status & PICOLCD_BOOTLOADER)) |
---|
289 | 277 | report = picolcd_out_report(REPORT_EXIT_KEYBOARD, data->hdev); |
---|
290 | | - buf += 10; |
---|
291 | | - cnt -= 10; |
---|
292 | | - } |
---|
293 | | - if (!report || report->maxfield != 1) |
---|
| 278 | + } else { |
---|
294 | 279 | return -EINVAL; |
---|
| 280 | + } |
---|
295 | 281 | |
---|
296 | | - while (cnt > 0 && (buf[cnt-1] == '\n' || buf[cnt-1] == '\r')) |
---|
297 | | - cnt--; |
---|
298 | | - if (cnt != 0) |
---|
| 282 | + if (!report || report->maxfield != 1) |
---|
299 | 283 | return -EINVAL; |
---|
300 | 284 | |
---|
301 | 285 | spin_lock_irqsave(&data->lock, flags); |
---|
.. | .. |
---|
550 | 534 | data = kzalloc(sizeof(struct picolcd_data), GFP_KERNEL); |
---|
551 | 535 | if (data == NULL) { |
---|
552 | 536 | hid_err(hdev, "can't allocate space for Minibox PicoLCD device data\n"); |
---|
553 | | - error = -ENOMEM; |
---|
554 | | - goto err_no_cleanup; |
---|
| 537 | + return -ENOMEM; |
---|
555 | 538 | } |
---|
556 | 539 | |
---|
557 | 540 | spin_lock_init(&data->lock); |
---|
.. | .. |
---|
613 | 596 | hid_hw_stop(hdev); |
---|
614 | 597 | err_cleanup_data: |
---|
615 | 598 | kfree(data); |
---|
616 | | -err_no_cleanup: |
---|
617 | | - hid_set_drvdata(hdev, NULL); |
---|
618 | | - |
---|
619 | 599 | return error; |
---|
620 | 600 | } |
---|
621 | 601 | |
---|
.. | .. |
---|
651 | 631 | picolcd_exit_cir(data); |
---|
652 | 632 | picolcd_exit_keys(data); |
---|
653 | 633 | |
---|
654 | | - hid_set_drvdata(hdev, NULL); |
---|
655 | 634 | mutex_destroy(&data->mutex); |
---|
656 | 635 | /* Finally, clean up the picolcd data itself */ |
---|
657 | 636 | kfree(data); |
---|