forked from luck/tmp_suning_uos_patched
33799a6d1a
debugfs_create_file returns NULL on error so an IS_ERR test is incorrect here and a NULL check is required. The Coccinelle semantic patch used to make this change is as follows: @@ expression e; @@ e = debugfs_create_file(...); if( - IS_ERR(e) + !e ) { <+... return - PTR_ERR(e) + -ENOMEM ; ...+> } Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com> Cc: julia.lawall@lip6.fr Cc: linux-mips@linux-mips.org Cc: linux-kernel@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/13834/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
82 lines
1.7 KiB
C
82 lines
1.7 KiB
C
/*
|
|
* Copyright (C) 2015 Imagination Technologies
|
|
* Author: Paul Burton <paul.burton@imgtec.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
* option) any later version.
|
|
*/
|
|
|
|
#include <asm/bcache.h>
|
|
#include <asm/debug.h>
|
|
#include <asm/uaccess.h>
|
|
#include <linux/debugfs.h>
|
|
#include <linux/init.h>
|
|
|
|
static ssize_t sc_prefetch_read(struct file *file, char __user *user_buf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
bool enabled = bc_prefetch_is_enabled();
|
|
char buf[3];
|
|
|
|
buf[0] = enabled ? 'Y' : 'N';
|
|
buf[1] = '\n';
|
|
buf[2] = 0;
|
|
|
|
return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
|
|
}
|
|
|
|
static ssize_t sc_prefetch_write(struct file *file,
|
|
const char __user *user_buf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
char buf[32];
|
|
ssize_t buf_size;
|
|
bool enabled;
|
|
int err;
|
|
|
|
buf_size = min(count, sizeof(buf) - 1);
|
|
if (copy_from_user(buf, user_buf, buf_size))
|
|
return -EFAULT;
|
|
|
|
buf[buf_size] = '\0';
|
|
err = strtobool(buf, &enabled);
|
|
if (err)
|
|
return err;
|
|
|
|
if (enabled)
|
|
bc_prefetch_enable();
|
|
else
|
|
bc_prefetch_disable();
|
|
|
|
return count;
|
|
}
|
|
|
|
static const struct file_operations sc_prefetch_fops = {
|
|
.open = simple_open,
|
|
.llseek = default_llseek,
|
|
.read = sc_prefetch_read,
|
|
.write = sc_prefetch_write,
|
|
};
|
|
|
|
static int __init sc_debugfs_init(void)
|
|
{
|
|
struct dentry *dir, *file;
|
|
|
|
if (!mips_debugfs_dir)
|
|
return -ENODEV;
|
|
|
|
dir = debugfs_create_dir("l2cache", mips_debugfs_dir);
|
|
if (IS_ERR(dir))
|
|
return PTR_ERR(dir);
|
|
|
|
file = debugfs_create_file("prefetch", S_IRUGO | S_IWUSR, dir,
|
|
NULL, &sc_prefetch_fops);
|
|
if (!file)
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
}
|
|
late_initcall(sc_debugfs_init);
|