From 392e3edc3d7e6d9f9ad1a3dee3a7efa858b9ee41 Mon Sep 17 00:00:00 2001 From: tzafrir Date: Wed, 6 Sep 2006 21:25:15 +0000 Subject: Fix problems reported by sparse git-svn-id: http://svn.digium.com/svn/zaptel/trunk@1423 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- xpp/card_fxo.c | 9 ++++----- xpp/card_fxs.c | 7 +++---- xpp/xbus-core.c | 9 ++++----- xpp/xbus-core.h | 2 +- xpp/xdefs.h | 1 + xpp/xpd.h | 5 ++++- xpp/xpp_zap.c | 14 ++++++-------- xpp/xproto.h | 2 +- 8 files changed, 24 insertions(+), 25 deletions(-) (limited to 'xpp') diff --git a/xpp/card_fxo.c b/xpp/card_fxo.c index 771676a..ed77684 100644 --- a/xpp/card_fxo.c +++ b/xpp/card_fxo.c @@ -489,7 +489,7 @@ static int FXO_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long a DBG("-- Setting echo registers: \n"); /* first off: check if this span is fxs. If not: -EINVALID */ if (copy_from_user(&echoregs.wctdm_struct, - (struct wctdm_echo_coefs*)arg, sizeof(echoregs.wctdm_struct))) + (struct wctdm_echo_coefs __user *)arg, sizeof(echoregs.wctdm_struct))) return -EFAULT; /* Set the ACIM register */ @@ -990,8 +990,7 @@ static int process_slic_cmdline(xpd_t *xpd, char *cmdline) static int proc_xpd_slic_write(struct file *file, const char __user *buffer, unsigned long count, void *data) { xpd_t *xpd = data; - const int LINE_LEN = 500; - char buf[LINE_LEN]; + char buf[MAX_PROC_WRITE]; char *p; int i; int ret; @@ -999,7 +998,7 @@ static int proc_xpd_slic_write(struct file *file, const char __user *buffer, uns if(!xpd) return -ENODEV; for(i = 0; i < count; /* noop */) { - for(p = buf; p < buf + LINE_LEN; p++) { /* read a line */ + for(p = buf; p < buf + MAX_PROC_WRITE; p++) { /* read a line */ if(i >= count) break; if(get_user(*p, buffer + i)) @@ -1008,7 +1007,7 @@ static int proc_xpd_slic_write(struct file *file, const char __user *buffer, uns if(*p == '\n' || *p == '\r') /* whatever */ break; } - if(p >= buf + LINE_LEN) + if(p >= buf + MAX_PROC_WRITE) return -E2BIG; *p = '\0'; ret = process_slic_cmdline(xpd, buf); diff --git a/xpp/card_fxs.c b/xpp/card_fxs.c index d5ade7b..9aaef63 100644 --- a/xpp/card_fxs.c +++ b/xpp/card_fxs.c @@ -989,8 +989,7 @@ static int process_slic_cmdline(xpd_t *xpd, char *cmdline) static int proc_xpd_slic_write(struct file *file, const char __user *buffer, unsigned long count, void *data) { xpd_t *xpd = data; - const int LINE_LEN = 500; - char buf[LINE_LEN]; + char buf[MAX_PROC_WRITE]; char *p; int i; int ret; @@ -998,7 +997,7 @@ static int proc_xpd_slic_write(struct file *file, const char __user *buffer, uns if(!xpd) return -ENODEV; for(i = 0; i < count; /* noop */) { - for(p = buf; p < buf + LINE_LEN; p++) { /* read a line */ + for(p = buf; p < buf + MAX_PROC_WRITE; p++) { /* read a line */ if(i >= count) break; if(get_user(*p, buffer + i)) @@ -1007,7 +1006,7 @@ static int proc_xpd_slic_write(struct file *file, const char __user *buffer, uns if(*p == '\n' || *p == '\r') /* whatever */ break; } - if(p >= buf + LINE_LEN) + if(p >= buf + MAX_PROC_WRITE) return -E2BIG; *p = '\0'; ret = process_slic_cmdline(xpd, buf); diff --git a/xpp/xbus-core.c b/xpp/xbus-core.c index 615d499..961c361 100644 --- a/xpp/xbus-core.c +++ b/xpp/xbus-core.c @@ -103,7 +103,7 @@ static atomic_t xpacket_count = ATOMIC_INIT(0); * Receive packets: * - Allocated/deallocated by xbus_xmiter */ -xpacket_t *xbus_packet_new(xbus_t *xbus, int flags) +xpacket_t *xbus_packet_new(xbus_t *xbus, gfp_t flags) { xpacket_t *pack; @@ -787,15 +787,14 @@ out: #ifdef PROTOCOL_DEBUG static int proc_xbus_command_write(struct file *file, const char __user *buffer, unsigned long count, void *data) { - const int NUM_SIZE = 100; - char buf[NUM_SIZE]; + char buf[MAX_PROC_WRITE]; xbus_t *xbus = data; xpacket_t *pack; char *p; byte *pack_contents; byte *q; - if(count >= NUM_SIZE) { + if(count >= MAX_PROC_WRITE) { ERR("%s: line too long\n", __FUNCTION__); return -EFBIG; } @@ -967,7 +966,7 @@ int __init xbus_core_init(void) return -ENOMEM; } #ifdef CONFIG_PROC_FS - proc_xbuses = create_proc_read_entry(PROC_XBUSES, 0444, xpp_proc_toplevel, read_proc_xbuses, 0); + proc_xbuses = create_proc_read_entry(PROC_XBUSES, 0444, xpp_proc_toplevel, read_proc_xbuses, NULL); if (!proc_xbuses) { ERR("Failed to create proc file %s\n", PROC_XBUSES); xbus_core_cleanup(); diff --git a/xpp/xbus-core.h b/xpp/xbus-core.h index 780c1b6..19f9fd7 100644 --- a/xpp/xbus-core.h +++ b/xpp/xbus-core.h @@ -30,7 +30,7 @@ int xbus_core_init(void); /* Initializer */ void xbus_core_shutdown(void); /* Terminator */ /* Packet handling */ -xpacket_t *xbus_packet_new(xbus_t *xbus, int flags); +xpacket_t *xbus_packet_new(xbus_t *xbus, gfp_t flags); void xbus_packet_free(xbus_t *xbus, xpacket_t *p); /* packet queues */ diff --git a/xpp/xdefs.h b/xpp/xdefs.h index 491e7b6..ab3670e 100644 --- a/xpp/xdefs.h +++ b/xpp/xdefs.h @@ -55,6 +55,7 @@ struct list_head { struct list_head *next; struct list_head *prev; }; #define IS_SET(x,i) (((x) & BIT(i)) != 0) #define BITMASK(i) (BIT(i) - 1) +#define MAX_PROC_WRITE 100 /* Largest buffer we allow writing our /proc files */ #define CHANNELS_PERXPD 30 /* Depends on xpp_line_t and protocol fields */ #define MAX_SPANNAME 20 /* From zaptel.h */ diff --git a/xpp/xpd.h b/xpp/xpd.h index 294559e..71db99e 100644 --- a/xpp/xpd.h +++ b/xpp/xpd.h @@ -37,6 +37,9 @@ #include #ifdef __KERNEL__ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) +typedef unsigned gfp_t; /* Added in 2.6.14 */ +#endif #define DEF_PARM(type,name,init,desc) \ type name = init; \ module_param(name, type, 0600); \ @@ -83,7 +86,7 @@ typedef struct packet_queue { struct xbus_ops { int (*packet_send)(xbus_t *xbus, xpacket_t *packet); - xpacket_t *(*packet_new)(xbus_t *xbus, int flags); + xpacket_t *(*packet_new)(xbus_t *xbus, gfp_t flags); void (*packet_free)(xbus_t *xbus, xpacket_t *p); }; diff --git a/xpp/xpp_zap.c b/xpp/xpp_zap.c index ffb8934..33ec4c6 100644 --- a/xpp/xpp_zap.c +++ b/xpp/xpp_zap.c @@ -716,8 +716,7 @@ int proc_sync_read(char *page, char **start, off_t off, int count, int *eof, voi static int proc_sync_write(struct file *file, const char __user *buffer, unsigned long count, void *data) { - const int NUM_SIZE = 100; - char buf[NUM_SIZE]; + char buf[MAX_PROC_WRITE]; int xbus_num; int xpd_num; xbus_t *xbus; @@ -726,7 +725,7 @@ static int proc_sync_write(struct file *file, const char __user *buffer, unsigne bool setit; // DBG("%s: count=%ld\n", __FUNCTION__, count); - if(count >= NUM_SIZE) + if(count >= MAX_PROC_WRITE) return -EINVAL; if(copy_from_user(buf, buffer, count)) return -EFAULT; @@ -793,13 +792,12 @@ int proc_xpd_ztregister_read(char *page, char **start, off_t off, int count, int static int proc_xpd_ztregister_write(struct file *file, const char __user *buffer, unsigned long count, void *data) { xpd_t *xpd = data; - const int NUM_SIZE = 100; - char buf[NUM_SIZE]; + char buf[MAX_PROC_WRITE]; bool zt_reg; int ret; BUG_ON(!xpd); - if(count >= NUM_SIZE) + if(count >= MAX_PROC_WRITE) return -EINVAL; if(copy_from_user(buf, buffer, count)) return -EFAULT; @@ -1103,7 +1101,7 @@ int xpp_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long arg) switch (cmd) { case ZT_ONHOOKTRANSFER: - if (get_user(x, (int *)arg)) + if (get_user(x, (int __user *)arg)) return -EFAULT; xpd->ohttimer[pos] = x << 3; xpd->idletxhookstate[pos] = FXS_LINE_CID; /* OHT mode when idle */ @@ -1114,7 +1112,7 @@ int xpp_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long arg) DBG("xpd=%d: ZT_ONHOOKTRANSFER (%d millis) chan=%d\n", xpd->id, x, pos); return -ENOTTY; case ZT_TONEDETECT: - if (get_user(x, (int *)arg)) + if (get_user(x, (int __user *)arg)) return -EFAULT; DBG("xpd=%d: ZT_TONEDETECT chan=%d: TONEDETECT_ON=%d TONEDETECT_MUTE=%d\n", xpd->id, pos, (x & ZT_TONEDETECT_ON), (x & ZT_TONEDETECT_MUTE)); diff --git a/xpp/xproto.h b/xpp/xproto.h index 4c6b924..7255e09 100644 --- a/xpp/xproto.h +++ b/xpp/xproto.h @@ -101,7 +101,7 @@ void xpd_set_addr(xpd_addr_t *addr, int xpd_num); ((p)->datalen + sizeof(xpd_addr_t) + 1) #define XENTRY(card,op) \ - [ XPROTO_NAME(card,op) ] { \ + [ XPROTO_NAME(card,op) ] = { \ .handler = XPROTO_HANDLER(card,op), \ .datalen = RPACKET_DATALEN(card,op), \ .name = #op, \ -- cgit v1.2.3