hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/hid/hid-sensor-custom.c
....@@ -1,15 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * hid-sensor-custom.c
34 * Copyright (c) 2015, Intel Corporation.
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms and conditions of the GNU General Public License,
7
- * version 2, as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope it will be useful, but WITHOUT
10
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
- * more details.
135 */
146
157 #include <linux/kernel.h>
....@@ -67,7 +59,7 @@
6759 u32 raw_len;
6860 } __packed;
6961
70
-static struct attribute hid_custom_attrs[] = {
62
+static struct attribute hid_custom_attrs[HID_CUSTOM_TOTAL_ATTRS] = {
7163 {.name = "name", .mode = S_IRUGO},
7264 {.name = "units", .mode = S_IRUGO},
7365 {.name = "unit-expo", .mode = S_IRUGO},
....@@ -157,8 +149,7 @@
157149 static ssize_t enable_sensor_show(struct device *dev,
158150 struct device_attribute *attr, char *buf)
159151 {
160
- struct platform_device *pdev = to_platform_device(dev);
161
- struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev);
152
+ struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev);
162153
163154 return sprintf(buf, "%d\n", sensor_inst->enable);
164155 }
....@@ -237,8 +228,7 @@
237228 struct device_attribute *attr,
238229 const char *buf, size_t count)
239230 {
240
- struct platform_device *pdev = to_platform_device(dev);
241
- struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev);
231
+ struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev);
242232 int value;
243233 int ret = -EINVAL;
244234
....@@ -283,8 +273,7 @@
283273 static ssize_t show_value(struct device *dev, struct device_attribute *attr,
284274 char *buf)
285275 {
286
- struct platform_device *pdev = to_platform_device(dev);
287
- struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev);
276
+ struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev);
288277 struct hid_sensor_hub_attribute_info *attribute;
289278 int index, usage, field_index;
290279 char name[HID_CUSTOM_NAME_LENGTH];
....@@ -324,7 +313,7 @@
324313
325314 while (i < ret) {
326315 if (i + attribute->size > ret) {
327
- len += snprintf(&buf[len],
316
+ len += scnprintf(&buf[len],
328317 PAGE_SIZE - len,
329318 "%d ", values[i]);
330319 break;
....@@ -347,10 +336,10 @@
347336 ++i;
348337 break;
349338 }
350
- len += snprintf(&buf[len], PAGE_SIZE - len,
339
+ len += scnprintf(&buf[len], PAGE_SIZE - len,
351340 "%lld ", value);
352341 }
353
- len += snprintf(&buf[len], PAGE_SIZE - len, "\n");
342
+ len += scnprintf(&buf[len], PAGE_SIZE - len, "\n");
354343
355344 return len;
356345 } else if (input)
....@@ -392,8 +381,7 @@
392381 static ssize_t store_value(struct device *dev, struct device_attribute *attr,
393382 const char *buf, size_t count)
394383 {
395
- struct platform_device *pdev = to_platform_device(dev);
396
- struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev);
384
+ struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev);
397385 int index, field_index, usage;
398386 char name[HID_CUSTOM_NAME_LENGTH];
399387 int value;
....@@ -699,7 +687,7 @@
699687 if (test_and_set_bit(0, &sensor_inst->misc_opened))
700688 return -EBUSY;
701689
702
- return nonseekable_open(inode, file);
690
+ return stream_open(inode, file);
703691 }
704692
705693 static __poll_t hid_sensor_custom_poll(struct file *file,