45 lines · c
1/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */2/*3 * Copyright (C) 2023 Intel Corporation4 * Copyright (C) 2012-2014 Intel Corporation5 * Copyright (C) 2013-2014 Intel Mobile Communications GmbH6 */7#define MVM_DEBUGFS_READ_FILE_OPS(name) \8static const struct file_operations iwl_dbgfs_##name##_ops = { \9 .read = iwl_dbgfs_##name##_read, \10 .open = simple_open, \11 .llseek = generic_file_llseek, \12}13 14#define MVM_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype) \15static ssize_t _iwl_dbgfs_##name##_write(struct file *file, \16 const char __user *user_buf, \17 size_t count, loff_t *ppos) \18{ \19 argtype *arg = file->private_data; \20 char buf[buflen] = {}; \21 size_t buf_size = min(count, sizeof(buf) - 1); \22 \23 if (copy_from_user(buf, user_buf, buf_size)) \24 return -EFAULT; \25 \26 return iwl_dbgfs_##name##_write(arg, buf, buf_size, ppos); \27} \28 29#define _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, buflen, argtype) \30MVM_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype) \31static const struct file_operations iwl_dbgfs_##name##_ops = { \32 .write = _iwl_dbgfs_##name##_write, \33 .read = iwl_dbgfs_##name##_read, \34 .open = simple_open, \35 .llseek = generic_file_llseek, \36};37 38#define _MVM_DEBUGFS_WRITE_FILE_OPS(name, buflen, argtype) \39MVM_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype) \40static const struct file_operations iwl_dbgfs_##name##_ops = { \41 .write = _iwl_dbgfs_##name##_write, \42 .open = simple_open, \43 .llseek = generic_file_llseek, \44};45