.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * hid-sensor-custom.c |
---|
3 | 4 | * 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. |
---|
13 | 5 | */ |
---|
14 | 6 | |
---|
15 | 7 | #include <linux/kernel.h> |
---|
.. | .. |
---|
67 | 59 | u32 raw_len; |
---|
68 | 60 | } __packed; |
---|
69 | 61 | |
---|
70 | | -static struct attribute hid_custom_attrs[] = { |
---|
| 62 | +static struct attribute hid_custom_attrs[HID_CUSTOM_TOTAL_ATTRS] = { |
---|
71 | 63 | {.name = "name", .mode = S_IRUGO}, |
---|
72 | 64 | {.name = "units", .mode = S_IRUGO}, |
---|
73 | 65 | {.name = "unit-expo", .mode = S_IRUGO}, |
---|
.. | .. |
---|
157 | 149 | static ssize_t enable_sensor_show(struct device *dev, |
---|
158 | 150 | struct device_attribute *attr, char *buf) |
---|
159 | 151 | { |
---|
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); |
---|
162 | 153 | |
---|
163 | 154 | return sprintf(buf, "%d\n", sensor_inst->enable); |
---|
164 | 155 | } |
---|
.. | .. |
---|
237 | 228 | struct device_attribute *attr, |
---|
238 | 229 | const char *buf, size_t count) |
---|
239 | 230 | { |
---|
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); |
---|
242 | 232 | int value; |
---|
243 | 233 | int ret = -EINVAL; |
---|
244 | 234 | |
---|
.. | .. |
---|
283 | 273 | static ssize_t show_value(struct device *dev, struct device_attribute *attr, |
---|
284 | 274 | char *buf) |
---|
285 | 275 | { |
---|
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); |
---|
288 | 277 | struct hid_sensor_hub_attribute_info *attribute; |
---|
289 | 278 | int index, usage, field_index; |
---|
290 | 279 | char name[HID_CUSTOM_NAME_LENGTH]; |
---|
.. | .. |
---|
324 | 313 | |
---|
325 | 314 | while (i < ret) { |
---|
326 | 315 | if (i + attribute->size > ret) { |
---|
327 | | - len += snprintf(&buf[len], |
---|
| 316 | + len += scnprintf(&buf[len], |
---|
328 | 317 | PAGE_SIZE - len, |
---|
329 | 318 | "%d ", values[i]); |
---|
330 | 319 | break; |
---|
.. | .. |
---|
347 | 336 | ++i; |
---|
348 | 337 | break; |
---|
349 | 338 | } |
---|
350 | | - len += snprintf(&buf[len], PAGE_SIZE - len, |
---|
| 339 | + len += scnprintf(&buf[len], PAGE_SIZE - len, |
---|
351 | 340 | "%lld ", value); |
---|
352 | 341 | } |
---|
353 | | - len += snprintf(&buf[len], PAGE_SIZE - len, "\n"); |
---|
| 342 | + len += scnprintf(&buf[len], PAGE_SIZE - len, "\n"); |
---|
354 | 343 | |
---|
355 | 344 | return len; |
---|
356 | 345 | } else if (input) |
---|
.. | .. |
---|
392 | 381 | static ssize_t store_value(struct device *dev, struct device_attribute *attr, |
---|
393 | 382 | const char *buf, size_t count) |
---|
394 | 383 | { |
---|
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); |
---|
397 | 385 | int index, field_index, usage; |
---|
398 | 386 | char name[HID_CUSTOM_NAME_LENGTH]; |
---|
399 | 387 | int value; |
---|
.. | .. |
---|
699 | 687 | if (test_and_set_bit(0, &sensor_inst->misc_opened)) |
---|
700 | 688 | return -EBUSY; |
---|
701 | 689 | |
---|
702 | | - return nonseekable_open(inode, file); |
---|
| 690 | + return stream_open(inode, file); |
---|
703 | 691 | } |
---|
704 | 692 | |
---|
705 | 693 | static __poll_t hid_sensor_custom_poll(struct file *file, |
---|