2005-04-16 22:20:36 +00:00
|
|
|
/* net/atm/resources.c - Statically allocated resources */
|
|
|
|
|
|
|
|
/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
|
|
|
|
|
|
|
|
/* Fixes
|
|
|
|
* Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
|
|
|
* 2002/01 - don't free the whole struct sock on sk->destruct time,
|
|
|
|
* use the default destruct function initialized by sock_init_data */
|
|
|
|
|
2010-01-26 11:40:00 +00:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/atmdev.h>
|
|
|
|
#include <linux/sonet.h>
|
|
|
|
#include <linux/kernel.h> /* for barrier */
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/bitops.h>
|
2006-01-11 20:17:47 +00:00
|
|
|
#include <linux/capability.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/delay.h>
|
2006-03-21 06:35:41 +00:00
|
|
|
#include <linux/mutex.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2006-03-21 06:35:41 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <net/sock.h> /* for struct sock */
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "resources.h"
|
|
|
|
#include "addr.h"
|
|
|
|
|
|
|
|
|
|
|
|
LIST_HEAD(atm_devs);
|
2006-03-21 06:35:41 +00:00
|
|
|
DEFINE_MUTEX(atm_dev_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static struct atm_dev *__alloc_atm_dev(const char *type)
|
|
|
|
{
|
|
|
|
struct atm_dev *dev;
|
|
|
|
|
2006-07-21 21:51:30 +00:00
|
|
|
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!dev)
|
|
|
|
return NULL;
|
|
|
|
dev->type = type;
|
|
|
|
dev->signal = ATM_PHY_SIG_UNKNOWN;
|
|
|
|
dev->link_rate = ATM_OC3_PCR;
|
|
|
|
spin_lock_init(&dev->lock);
|
|
|
|
INIT_LIST_HEAD(&dev->local);
|
2005-10-07 05:19:28 +00:00
|
|
|
INIT_LIST_HEAD(&dev->lecs);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct atm_dev *__atm_dev_lookup(int number)
|
|
|
|
{
|
|
|
|
struct atm_dev *dev;
|
|
|
|
struct list_head *p;
|
|
|
|
|
|
|
|
list_for_each(p, &atm_devs) {
|
|
|
|
dev = list_entry(p, struct atm_dev, dev_list);
|
2005-11-30 00:16:21 +00:00
|
|
|
if (dev->number == number) {
|
2005-04-16 22:20:36 +00:00
|
|
|
atm_dev_hold(dev);
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct atm_dev *atm_dev_lookup(int number)
|
|
|
|
{
|
|
|
|
struct atm_dev *dev;
|
|
|
|
|
2006-03-21 06:35:41 +00:00
|
|
|
mutex_lock(&atm_dev_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
dev = __atm_dev_lookup(number);
|
2006-03-21 06:35:41 +00:00
|
|
|
mutex_unlock(&atm_dev_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
return dev;
|
|
|
|
}
|
2010-01-26 11:40:16 +00:00
|
|
|
EXPORT_SYMBOL(atm_dev_lookup);
|
2005-11-30 00:16:41 +00:00
|
|
|
|
2010-12-08 19:40:47 +00:00
|
|
|
struct atm_dev *atm_dev_register(const char *type, struct device *parent,
|
|
|
|
const struct atmdev_ops *ops, int number,
|
|
|
|
unsigned long *flags)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct atm_dev *dev, *inuse;
|
|
|
|
|
|
|
|
dev = __alloc_atm_dev(type);
|
|
|
|
if (!dev) {
|
2010-01-26 11:40:00 +00:00
|
|
|
pr_err("no space for dev %s\n", type);
|
2005-04-16 22:20:36 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2006-03-21 06:35:41 +00:00
|
|
|
mutex_lock(&atm_dev_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (number != -1) {
|
2010-01-26 11:40:16 +00:00
|
|
|
inuse = __atm_dev_lookup(number);
|
|
|
|
if (inuse) {
|
2005-04-16 22:20:36 +00:00
|
|
|
atm_dev_put(inuse);
|
2006-03-21 06:35:41 +00:00
|
|
|
mutex_unlock(&atm_dev_mutex);
|
2005-04-21 23:48:26 +00:00
|
|
|
kfree(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
dev->number = number;
|
|
|
|
} else {
|
|
|
|
dev->number = 0;
|
|
|
|
while ((inuse = __atm_dev_lookup(dev->number))) {
|
|
|
|
atm_dev_put(inuse);
|
|
|
|
dev->number++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->ops = ops;
|
|
|
|
if (flags)
|
|
|
|
dev->flags = *flags;
|
|
|
|
else
|
|
|
|
memset(&dev->flags, 0, sizeof(dev->flags));
|
|
|
|
memset(&dev->stats, 0, sizeof(dev->stats));
|
2017-07-04 12:53:01 +00:00
|
|
|
refcount_set(&dev->refcnt, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (atm_proc_dev_register(dev) < 0) {
|
2010-01-26 11:40:00 +00:00
|
|
|
pr_err("atm_proc_dev_register failed for dev %s\n", type);
|
2006-06-29 19:36:34 +00:00
|
|
|
goto out_fail;
|
|
|
|
}
|
|
|
|
|
2010-12-08 19:40:47 +00:00
|
|
|
if (atm_register_sysfs(dev, parent) < 0) {
|
2010-01-26 11:40:00 +00:00
|
|
|
pr_err("atm_register_sysfs failed for dev %s\n", type);
|
2006-06-29 19:36:34 +00:00
|
|
|
atm_proc_dev_deregister(dev);
|
|
|
|
goto out_fail;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2006-06-29 19:36:34 +00:00
|
|
|
|
2005-11-30 00:16:21 +00:00
|
|
|
list_add_tail(&dev->dev_list, &atm_devs);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-29 19:36:34 +00:00
|
|
|
out:
|
|
|
|
mutex_unlock(&atm_dev_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
return dev;
|
2006-06-29 19:36:34 +00:00
|
|
|
|
|
|
|
out_fail:
|
|
|
|
kfree(dev);
|
|
|
|
dev = NULL;
|
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2010-01-26 11:40:16 +00:00
|
|
|
EXPORT_SYMBOL(atm_dev_register);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
void atm_dev_deregister(struct atm_dev *dev)
|
|
|
|
{
|
2005-11-30 00:16:41 +00:00
|
|
|
BUG_ON(test_bit(ATM_DF_REMOVED, &dev->flags));
|
|
|
|
set_bit(ATM_DF_REMOVED, &dev->flags);
|
|
|
|
|
|
|
|
/*
|
2007-02-09 14:24:29 +00:00
|
|
|
* if we remove current device from atm_devs list, new device
|
|
|
|
* with same number can appear, such we need deregister proc,
|
2005-11-30 00:16:41 +00:00
|
|
|
* release async all vccs and remove them from vccs list too
|
|
|
|
*/
|
2006-03-21 06:35:41 +00:00
|
|
|
mutex_lock(&atm_dev_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
list_del(&dev->dev_list);
|
2006-03-21 06:35:41 +00:00
|
|
|
mutex_unlock(&atm_dev_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-11-30 00:16:41 +00:00
|
|
|
atm_dev_release_vccs(dev);
|
2006-06-29 19:36:34 +00:00
|
|
|
atm_unregister_sysfs(dev);
|
2005-11-30 00:16:41 +00:00
|
|
|
atm_proc_dev_deregister(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-11-30 00:16:41 +00:00
|
|
|
atm_dev_put(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2010-01-26 11:40:16 +00:00
|
|
|
EXPORT_SYMBOL(atm_dev_deregister);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static void copy_aal_stats(struct k_atm_aal_stats *from,
|
|
|
|
struct atm_aal_stats *to)
|
|
|
|
{
|
|
|
|
#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
|
|
|
|
__AAL_STAT_ITEMS
|
|
|
|
#undef __HANDLE_ITEM
|
|
|
|
}
|
|
|
|
|
|
|
|
static void subtract_aal_stats(struct k_atm_aal_stats *from,
|
|
|
|
struct atm_aal_stats *to)
|
|
|
|
{
|
|
|
|
#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
|
|
|
|
__AAL_STAT_ITEMS
|
|
|
|
#undef __HANDLE_ITEM
|
|
|
|
}
|
|
|
|
|
2010-01-26 11:40:16 +00:00
|
|
|
static int fetch_stats(struct atm_dev *dev, struct atm_dev_stats __user *arg,
|
|
|
|
int zero)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct atm_dev_stats tmp;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
copy_aal_stats(&dev->stats.aal0, &tmp.aal0);
|
|
|
|
copy_aal_stats(&dev->stats.aal34, &tmp.aal34);
|
|
|
|
copy_aal_stats(&dev->stats.aal5, &tmp.aal5);
|
|
|
|
if (arg)
|
|
|
|
error = copy_to_user(arg, &tmp, sizeof(tmp));
|
|
|
|
if (zero && !error) {
|
|
|
|
subtract_aal_stats(&dev->stats.aal0, &tmp.aal0);
|
|
|
|
subtract_aal_stats(&dev->stats.aal34, &tmp.aal34);
|
|
|
|
subtract_aal_stats(&dev->stats.aal5, &tmp.aal5);
|
|
|
|
}
|
|
|
|
return error ? -EFAULT : 0;
|
|
|
|
}
|
|
|
|
|
atm: 32-bit ioctl compatibility
We lack compat ioctl support through most of the ATM code. This patch
deals with most of it, and I can now at least use BR2684 and PPPoATM
with 32-bit userspace.
I haven't added a .compat_ioctl method to struct atm_ioctl, because
AFAICT none of the current users need any conversion -- so we can just
call the ->ioctl() method in every case. I looked at br2684, clip, lec,
mpc, pppoatm and atmtcp.
In svc_compat_ioctl() the only mangling which is needed is to change
COMPAT_ATM_ADDPARTY to ATM_ADDPARTY. Although it's defined as
_IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
it doesn't actually _take_ a struct atm_iobuf as an argument -- it takes
a struct sockaddr_atmsvc, which _is_ the same between 32-bit and 64-bit
code, so doesn't need conversion.
Almost all of vcc_ioctl() would have been identical, so I converted that
into a core do_vcc_ioctl() function with an 'int compat' argument.
I've done the same with atm_dev_ioctl(), where there _are_ a few
differences, but still it's relatively contained and there would
otherwise have been a lot of duplication.
I haven't done any of the actual device-specific ioctls, although I've
added a compat_ioctl method to struct atmdev_ops.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-12-04 06:12:38 +00:00
|
|
|
int atm_dev_ioctl(unsigned int cmd, void __user *arg, int compat)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
void __user *buf;
|
|
|
|
int error, len, number, size = 0;
|
|
|
|
struct atm_dev *dev;
|
|
|
|
struct list_head *p;
|
|
|
|
int *tmp_buf, *tmp_p;
|
atm: 32-bit ioctl compatibility
We lack compat ioctl support through most of the ATM code. This patch
deals with most of it, and I can now at least use BR2684 and PPPoATM
with 32-bit userspace.
I haven't added a .compat_ioctl method to struct atm_ioctl, because
AFAICT none of the current users need any conversion -- so we can just
call the ->ioctl() method in every case. I looked at br2684, clip, lec,
mpc, pppoatm and atmtcp.
In svc_compat_ioctl() the only mangling which is needed is to change
COMPAT_ATM_ADDPARTY to ATM_ADDPARTY. Although it's defined as
_IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
it doesn't actually _take_ a struct atm_iobuf as an argument -- it takes
a struct sockaddr_atmsvc, which _is_ the same between 32-bit and 64-bit
code, so doesn't need conversion.
Almost all of vcc_ioctl() would have been identical, so I converted that
into a core do_vcc_ioctl() function with an 'int compat' argument.
I've done the same with atm_dev_ioctl(), where there _are_ a few
differences, but still it's relatively contained and there would
otherwise have been a lot of duplication.
I haven't done any of the actual device-specific ioctls, although I've
added a compat_ioctl method to struct atmdev_ops.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-12-04 06:12:38 +00:00
|
|
|
int __user *sioc_len;
|
|
|
|
int __user *iobuf_len;
|
|
|
|
|
|
|
|
#ifndef CONFIG_COMPAT
|
|
|
|
compat = 0; /* Just so the compiler _knows_ */
|
|
|
|
#endif
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
switch (cmd) {
|
2010-01-26 11:40:16 +00:00
|
|
|
case ATM_GETNAMES:
|
|
|
|
if (compat) {
|
atm: 32-bit ioctl compatibility
We lack compat ioctl support through most of the ATM code. This patch
deals with most of it, and I can now at least use BR2684 and PPPoATM
with 32-bit userspace.
I haven't added a .compat_ioctl method to struct atm_ioctl, because
AFAICT none of the current users need any conversion -- so we can just
call the ->ioctl() method in every case. I looked at br2684, clip, lec,
mpc, pppoatm and atmtcp.
In svc_compat_ioctl() the only mangling which is needed is to change
COMPAT_ATM_ADDPARTY to ATM_ADDPARTY. Although it's defined as
_IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
it doesn't actually _take_ a struct atm_iobuf as an argument -- it takes
a struct sockaddr_atmsvc, which _is_ the same between 32-bit and 64-bit
code, so doesn't need conversion.
Almost all of vcc_ioctl() would have been identical, so I converted that
into a core do_vcc_ioctl() function with an 'int compat' argument.
I've done the same with atm_dev_ioctl(), where there _are_ a few
differences, but still it's relatively contained and there would
otherwise have been a lot of duplication.
I haven't done any of the actual device-specific ioctls, although I've
added a compat_ioctl method to struct atmdev_ops.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-12-04 06:12:38 +00:00
|
|
|
#ifdef CONFIG_COMPAT
|
2010-01-26 11:40:16 +00:00
|
|
|
struct compat_atm_iobuf __user *ciobuf = arg;
|
|
|
|
compat_uptr_t cbuf;
|
|
|
|
iobuf_len = &ciobuf->length;
|
|
|
|
if (get_user(cbuf, &ciobuf->buffer))
|
|
|
|
return -EFAULT;
|
|
|
|
buf = compat_ptr(cbuf);
|
atm: 32-bit ioctl compatibility
We lack compat ioctl support through most of the ATM code. This patch
deals with most of it, and I can now at least use BR2684 and PPPoATM
with 32-bit userspace.
I haven't added a .compat_ioctl method to struct atm_ioctl, because
AFAICT none of the current users need any conversion -- so we can just
call the ->ioctl() method in every case. I looked at br2684, clip, lec,
mpc, pppoatm and atmtcp.
In svc_compat_ioctl() the only mangling which is needed is to change
COMPAT_ATM_ADDPARTY to ATM_ADDPARTY. Although it's defined as
_IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
it doesn't actually _take_ a struct atm_iobuf as an argument -- it takes
a struct sockaddr_atmsvc, which _is_ the same between 32-bit and 64-bit
code, so doesn't need conversion.
Almost all of vcc_ioctl() would have been identical, so I converted that
into a core do_vcc_ioctl() function with an 'int compat' argument.
I've done the same with atm_dev_ioctl(), where there _are_ a few
differences, but still it's relatively contained and there would
otherwise have been a lot of duplication.
I haven't done any of the actual device-specific ioctls, although I've
added a compat_ioctl method to struct atmdev_ops.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-12-04 06:12:38 +00:00
|
|
|
#endif
|
2010-01-26 11:40:16 +00:00
|
|
|
} else {
|
|
|
|
struct atm_iobuf __user *iobuf = arg;
|
|
|
|
iobuf_len = &iobuf->length;
|
|
|
|
if (get_user(buf, &iobuf->buffer))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EFAULT;
|
2010-01-26 11:40:16 +00:00
|
|
|
}
|
|
|
|
if (get_user(len, iobuf_len))
|
|
|
|
return -EFAULT;
|
|
|
|
mutex_lock(&atm_dev_mutex);
|
|
|
|
list_for_each(p, &atm_devs)
|
|
|
|
size += sizeof(int);
|
|
|
|
if (size > len) {
|
2006-03-21 06:35:41 +00:00
|
|
|
mutex_unlock(&atm_dev_mutex);
|
2010-01-26 11:40:16 +00:00
|
|
|
return -E2BIG;
|
|
|
|
}
|
|
|
|
tmp_buf = kmalloc(size, GFP_ATOMIC);
|
|
|
|
if (!tmp_buf) {
|
|
|
|
mutex_unlock(&atm_dev_mutex);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
tmp_p = tmp_buf;
|
|
|
|
list_for_each(p, &atm_devs) {
|
|
|
|
dev = list_entry(p, struct atm_dev, dev_list);
|
|
|
|
*tmp_p++ = dev->number;
|
|
|
|
}
|
|
|
|
mutex_unlock(&atm_dev_mutex);
|
|
|
|
error = ((copy_to_user(buf, tmp_buf, size)) ||
|
|
|
|
put_user(size, iobuf_len))
|
|
|
|
? -EFAULT : 0;
|
|
|
|
kfree(tmp_buf);
|
|
|
|
return error;
|
|
|
|
default:
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
atm: 32-bit ioctl compatibility
We lack compat ioctl support through most of the ATM code. This patch
deals with most of it, and I can now at least use BR2684 and PPPoATM
with 32-bit userspace.
I haven't added a .compat_ioctl method to struct atm_ioctl, because
AFAICT none of the current users need any conversion -- so we can just
call the ->ioctl() method in every case. I looked at br2684, clip, lec,
mpc, pppoatm and atmtcp.
In svc_compat_ioctl() the only mangling which is needed is to change
COMPAT_ATM_ADDPARTY to ATM_ADDPARTY. Although it's defined as
_IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
it doesn't actually _take_ a struct atm_iobuf as an argument -- it takes
a struct sockaddr_atmsvc, which _is_ the same between 32-bit and 64-bit
code, so doesn't need conversion.
Almost all of vcc_ioctl() would have been identical, so I converted that
into a core do_vcc_ioctl() function with an 'int compat' argument.
I've done the same with atm_dev_ioctl(), where there _are_ a few
differences, but still it's relatively contained and there would
otherwise have been a lot of duplication.
I haven't done any of the actual device-specific ioctls, although I've
added a compat_ioctl method to struct atmdev_ops.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-12-04 06:12:38 +00:00
|
|
|
if (compat) {
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
struct compat_atmif_sioc __user *csioc = arg;
|
|
|
|
compat_uptr_t carg;
|
|
|
|
|
|
|
|
sioc_len = &csioc->length;
|
|
|
|
if (get_user(carg, &csioc->arg))
|
|
|
|
return -EFAULT;
|
|
|
|
buf = compat_ptr(carg);
|
|
|
|
|
|
|
|
if (get_user(len, &csioc->length))
|
|
|
|
return -EFAULT;
|
|
|
|
if (get_user(number, &csioc->number))
|
|
|
|
return -EFAULT;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
struct atmif_sioc __user *sioc = arg;
|
|
|
|
|
|
|
|
sioc_len = &sioc->length;
|
|
|
|
if (get_user(buf, &sioc->arg))
|
|
|
|
return -EFAULT;
|
|
|
|
if (get_user(len, &sioc->length))
|
|
|
|
return -EFAULT;
|
|
|
|
if (get_user(number, &sioc->number))
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
2010-01-26 11:40:16 +00:00
|
|
|
|
|
|
|
dev = try_then_request_module(atm_dev_lookup(number), "atm-device-%d",
|
|
|
|
number);
|
|
|
|
if (!dev)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
2007-02-09 14:24:29 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
switch (cmd) {
|
2010-01-26 11:40:16 +00:00
|
|
|
case ATM_GETTYPE:
|
|
|
|
size = strlen(dev->type) + 1;
|
|
|
|
if (copy_to_user(buf, dev->type, size)) {
|
|
|
|
error = -EFAULT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ATM_GETESI:
|
|
|
|
size = ESI_LEN;
|
|
|
|
if (copy_to_user(buf, dev->esi, size)) {
|
|
|
|
error = -EFAULT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ATM_SETESI:
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ESI_LEN; i++)
|
|
|
|
if (dev->esi[i]) {
|
|
|
|
error = -EEXIST;
|
2005-04-16 22:20:36 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2010-01-26 11:40:16 +00:00
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case ATM_SETESIF:
|
|
|
|
{
|
|
|
|
unsigned char esi[ESI_LEN];
|
|
|
|
|
|
|
|
if (!capable(CAP_NET_ADMIN)) {
|
|
|
|
error = -EPERM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (copy_from_user(esi, buf, ESI_LEN)) {
|
|
|
|
error = -EFAULT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
memcpy(dev->esi, esi, ESI_LEN);
|
|
|
|
error = ESI_LEN;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
case ATM_GETSTATZ:
|
|
|
|
if (!capable(CAP_NET_ADMIN)) {
|
|
|
|
error = -EPERM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case ATM_GETSTAT:
|
|
|
|
size = sizeof(struct atm_dev_stats);
|
|
|
|
error = fetch_stats(dev, buf, cmd == ATM_GETSTATZ);
|
|
|
|
if (error)
|
|
|
|
goto done;
|
|
|
|
break;
|
|
|
|
case ATM_GETCIRANGE:
|
|
|
|
size = sizeof(struct atm_cirange);
|
|
|
|
if (copy_to_user(buf, &dev->ci_range, size)) {
|
|
|
|
error = -EFAULT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ATM_GETLINKRATE:
|
|
|
|
size = sizeof(int);
|
|
|
|
if (copy_to_user(buf, &dev->link_rate, size)) {
|
|
|
|
error = -EFAULT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ATM_RSTADDR:
|
|
|
|
if (!capable(CAP_NET_ADMIN)) {
|
|
|
|
error = -EPERM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
atm_reset_addr(dev, ATM_ADDR_LOCAL);
|
|
|
|
break;
|
|
|
|
case ATM_ADDADDR:
|
|
|
|
case ATM_DELADDR:
|
|
|
|
case ATM_ADDLECSADDR:
|
|
|
|
case ATM_DELLECSADDR:
|
|
|
|
{
|
|
|
|
struct sockaddr_atmsvc addr;
|
|
|
|
|
|
|
|
if (!capable(CAP_NET_ADMIN)) {
|
|
|
|
error = -EPERM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy_from_user(&addr, buf, sizeof(addr))) {
|
|
|
|
error = -EFAULT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (cmd == ATM_ADDADDR || cmd == ATM_ADDLECSADDR)
|
|
|
|
error = atm_add_addr(dev, &addr,
|
|
|
|
(cmd == ATM_ADDADDR ?
|
2005-10-07 05:19:28 +00:00
|
|
|
ATM_ADDR_LOCAL : ATM_ADDR_LECS));
|
2010-01-26 11:40:16 +00:00
|
|
|
else
|
|
|
|
error = atm_del_addr(dev, &addr,
|
|
|
|
(cmd == ATM_DELADDR ?
|
|
|
|
ATM_ADDR_LOCAL : ATM_ADDR_LECS));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
case ATM_GETADDR:
|
|
|
|
case ATM_GETLECSADDR:
|
|
|
|
error = atm_get_addr(dev, buf, len,
|
|
|
|
(cmd == ATM_GETADDR ?
|
|
|
|
ATM_ADDR_LOCAL : ATM_ADDR_LECS));
|
|
|
|
if (error < 0)
|
|
|
|
goto done;
|
|
|
|
size = error;
|
|
|
|
/* may return 0, but later on size == 0 means "don't
|
|
|
|
write the length" */
|
|
|
|
error = put_user(size, sioc_len) ? -EFAULT : 0;
|
|
|
|
goto done;
|
|
|
|
case ATM_SETLOOP:
|
|
|
|
if (__ATM_LM_XTRMT((int) (unsigned long) buf) &&
|
|
|
|
__ATM_LM_XTLOC((int) (unsigned long) buf) >
|
|
|
|
__ATM_LM_XTRMT((int) (unsigned long) buf)) {
|
|
|
|
error = -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
goto done;
|
2010-01-26 11:40:16 +00:00
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case ATM_SETCIRANGE:
|
|
|
|
case SONET_GETSTATZ:
|
|
|
|
case SONET_SETDIAG:
|
|
|
|
case SONET_CLRDIAG:
|
|
|
|
case SONET_SETFRAMING:
|
|
|
|
if (!capable(CAP_NET_ADMIN)) {
|
|
|
|
error = -EPERM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
if (compat) {
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
if (!dev->ops->compat_ioctl) {
|
2005-04-16 22:20:36 +00:00
|
|
|
error = -EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
2010-01-26 11:40:16 +00:00
|
|
|
size = dev->ops->compat_ioctl(dev, cmd, buf);
|
atm: 32-bit ioctl compatibility
We lack compat ioctl support through most of the ATM code. This patch
deals with most of it, and I can now at least use BR2684 and PPPoATM
with 32-bit userspace.
I haven't added a .compat_ioctl method to struct atm_ioctl, because
AFAICT none of the current users need any conversion -- so we can just
call the ->ioctl() method in every case. I looked at br2684, clip, lec,
mpc, pppoatm and atmtcp.
In svc_compat_ioctl() the only mangling which is needed is to change
COMPAT_ATM_ADDPARTY to ATM_ADDPARTY. Although it's defined as
_IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
it doesn't actually _take_ a struct atm_iobuf as an argument -- it takes
a struct sockaddr_atmsvc, which _is_ the same between 32-bit and 64-bit
code, so doesn't need conversion.
Almost all of vcc_ioctl() would have been identical, so I converted that
into a core do_vcc_ioctl() function with an 'int compat' argument.
I've done the same with atm_dev_ioctl(), where there _are_ a few
differences, but still it's relatively contained and there would
otherwise have been a lot of duplication.
I haven't done any of the actual device-specific ioctls, although I've
added a compat_ioctl method to struct atmdev_ops.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-12-04 06:12:38 +00:00
|
|
|
#endif
|
2010-01-26 11:40:16 +00:00
|
|
|
} else {
|
|
|
|
if (!dev->ops->ioctl) {
|
|
|
|
error = -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2010-01-26 11:40:16 +00:00
|
|
|
size = dev->ops->ioctl(dev, cmd, buf);
|
|
|
|
}
|
|
|
|
if (size < 0) {
|
2012-08-26 21:23:13 +00:00
|
|
|
error = (size == -ENOIOCTLCMD ? -ENOTTY : size);
|
2010-01-26 11:40:16 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2007-02-09 14:24:29 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (size)
|
2010-01-26 11:40:16 +00:00
|
|
|
error = put_user(size, sioc_len) ? -EFAULT : 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
|
|
|
error = 0;
|
|
|
|
done:
|
|
|
|
atm_dev_put(dev);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *atm_dev_seq_start(struct seq_file *seq, loff_t *pos)
|
|
|
|
{
|
2007-02-09 14:24:29 +00:00
|
|
|
mutex_lock(&atm_dev_mutex);
|
2010-02-08 23:21:51 +00:00
|
|
|
return seq_list_start_head(&atm_devs, *pos);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void atm_dev_seq_stop(struct seq_file *seq, void *v)
|
|
|
|
{
|
2007-02-09 14:24:29 +00:00
|
|
|
mutex_unlock(&atm_dev_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2007-02-09 14:24:29 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
void *atm_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
|
|
|
{
|
2010-02-08 23:21:51 +00:00
|
|
|
return seq_list_next(v, &atm_devs, pos);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|