2019-05-20 07:19:02 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* ISA Plug & Play support
|
2007-10-15 07:50:19 +00:00
|
|
|
* Copyright (c) by Jaroslav Kysela <perex@perex.cz>
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/isapnp.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/init.h>
|
2016-07-14 20:22:57 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
extern struct pnp_protocol isapnp_protocol;
|
|
|
|
|
|
|
|
static struct proc_dir_entry *isapnp_proc_bus_dir = NULL;
|
|
|
|
|
|
|
|
static loff_t isapnp_proc_bus_lseek(struct file *file, loff_t off, int whence)
|
|
|
|
{
|
2013-06-23 08:09:11 +00:00
|
|
|
return fixed_size_llseek(file, off, whence, 256);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-07-26 17:41:20 +00:00
|
|
|
static ssize_t isapnp_proc_bus_read(struct file *file, char __user * buf,
|
|
|
|
size_t nbytes, loff_t * ppos)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2013-03-31 22:16:14 +00:00
|
|
|
struct pnp_dev *dev = PDE_DATA(file_inode(file));
|
2005-04-16 22:20:36 +00:00
|
|
|
int pos = *ppos;
|
|
|
|
int cnt, size = 256;
|
|
|
|
|
|
|
|
if (pos >= size)
|
|
|
|
return 0;
|
|
|
|
if (nbytes >= size)
|
|
|
|
nbytes = size;
|
|
|
|
if (pos + nbytes > size)
|
|
|
|
nbytes = size - pos;
|
|
|
|
cnt = nbytes;
|
|
|
|
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 02:57:57 +00:00
|
|
|
if (!access_ok(buf, cnt))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
isapnp_cfg_begin(dev->card->number, dev->number);
|
2007-07-26 17:41:20 +00:00
|
|
|
for (; pos < 256 && cnt > 0; pos++, buf++, cnt--) {
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned char val;
|
|
|
|
val = isapnp_read_byte(pos);
|
|
|
|
__put_user(val, buf);
|
|
|
|
}
|
|
|
|
isapnp_cfg_end();
|
|
|
|
|
|
|
|
*ppos = pos;
|
|
|
|
return nbytes;
|
|
|
|
}
|
|
|
|
|
2007-07-26 17:41:20 +00:00
|
|
|
static const struct file_operations isapnp_proc_bus_file_operations = {
|
2008-04-29 08:02:35 +00:00
|
|
|
.owner = THIS_MODULE,
|
2007-07-26 17:41:20 +00:00
|
|
|
.llseek = isapnp_proc_bus_lseek,
|
|
|
|
.read = isapnp_proc_bus_read,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int isapnp_proc_attach_device(struct pnp_dev *dev)
|
|
|
|
{
|
|
|
|
struct pnp_card *bus = dev->card;
|
|
|
|
struct proc_dir_entry *de, *e;
|
|
|
|
char name[16];
|
|
|
|
|
|
|
|
if (!(de = bus->procdir)) {
|
|
|
|
sprintf(name, "%02x", bus->number);
|
|
|
|
de = bus->procdir = proc_mkdir(name, isapnp_proc_bus_dir);
|
|
|
|
if (!de)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
sprintf(name, "%02x", dev->number);
|
2008-04-29 08:02:35 +00:00
|
|
|
e = dev->procent = proc_create_data(name, S_IFREG | S_IRUGO, de,
|
|
|
|
&isapnp_proc_bus_file_operations, dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!e)
|
|
|
|
return -ENOMEM;
|
2013-04-11 23:38:51 +00:00
|
|
|
proc_set_size(e, 256);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __init isapnp_proc_init(void)
|
|
|
|
{
|
|
|
|
struct pnp_dev *dev;
|
2007-07-26 17:41:21 +00:00
|
|
|
|
2008-04-29 08:01:41 +00:00
|
|
|
isapnp_proc_bus_dir = proc_mkdir("bus/isapnp", NULL);
|
2007-07-26 17:41:20 +00:00
|
|
|
protocol_for_each_dev(&isapnp_protocol, dev) {
|
2005-04-16 22:20:36 +00:00
|
|
|
isapnp_proc_attach_device(dev);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|