diff options
author | Tobias Klauser <tklauser@nuerscht.ch> | 2006-03-31 05:30:56 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-31 15:18:56 -0500 |
commit | b0b4ed728cdd0c7204392b0c18857e4a99917aa5 (patch) | |
tree | cfb0dd03b93ac310f5f02a0452cb83bf7e6628ef /drivers/char | |
parent | 993dfa8776308dcfd311cf77a3bbed4aa11e9868 (diff) |
[PATCH] drivers/char/[i]stallion: Clean up kmalloc usage
Delete two useless kmalloc wrappers and use kmalloc/kzalloc. Some weird
NULL checks are also simplified.
Signed-off-by: Tobias Klauser <tklauser@nuerscht.ch>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/char')
-rw-r--r-- | drivers/char/istallion.c | 32 | ||||
-rw-r--r-- | drivers/char/stallion.c | 46 |
2 files changed, 24 insertions, 54 deletions
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c index e5247f85a446..ef20c1fc9c4c 100644 --- a/drivers/char/istallion.c +++ b/drivers/char/istallion.c | |||
@@ -706,7 +706,6 @@ static int stli_portcmdstats(stliport_t *portp); | |||
706 | static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp); | 706 | static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp); |
707 | static int stli_getportstruct(stliport_t __user *arg); | 707 | static int stli_getportstruct(stliport_t __user *arg); |
708 | static int stli_getbrdstruct(stlibrd_t __user *arg); | 708 | static int stli_getbrdstruct(stlibrd_t __user *arg); |
709 | static void *stli_memalloc(int len); | ||
710 | static stlibrd_t *stli_allocbrd(void); | 709 | static stlibrd_t *stli_allocbrd(void); |
711 | 710 | ||
712 | static void stli_ecpinit(stlibrd_t *brdp); | 711 | static void stli_ecpinit(stlibrd_t *brdp); |
@@ -997,17 +996,6 @@ static int stli_parsebrd(stlconf_t *confp, char **argp) | |||
997 | 996 | ||
998 | /*****************************************************************************/ | 997 | /*****************************************************************************/ |
999 | 998 | ||
1000 | /* | ||
1001 | * Local driver kernel malloc routine. | ||
1002 | */ | ||
1003 | |||
1004 | static void *stli_memalloc(int len) | ||
1005 | { | ||
1006 | return((void *) kmalloc(len, GFP_KERNEL)); | ||
1007 | } | ||
1008 | |||
1009 | /*****************************************************************************/ | ||
1010 | |||
1011 | static int stli_open(struct tty_struct *tty, struct file *filp) | 999 | static int stli_open(struct tty_struct *tty, struct file *filp) |
1012 | { | 1000 | { |
1013 | stlibrd_t *brdp; | 1001 | stlibrd_t *brdp; |
@@ -3227,13 +3215,12 @@ static int stli_initports(stlibrd_t *brdp) | |||
3227 | #endif | 3215 | #endif |
3228 | 3216 | ||
3229 | for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) { | 3217 | for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) { |
3230 | portp = (stliport_t *) stli_memalloc(sizeof(stliport_t)); | 3218 | portp = kzalloc(sizeof(stliport_t), GFP_KERNEL); |
3231 | if (portp == (stliport_t *) NULL) { | 3219 | if (!portp) { |
3232 | printk("STALLION: failed to allocate port structure\n"); | 3220 | printk("STALLION: failed to allocate port structure\n"); |
3233 | continue; | 3221 | continue; |
3234 | } | 3222 | } |
3235 | 3223 | ||
3236 | memset(portp, 0, sizeof(stliport_t)); | ||
3237 | portp->magic = STLI_PORTMAGIC; | 3224 | portp->magic = STLI_PORTMAGIC; |
3238 | portp->portnr = i; | 3225 | portp->portnr = i; |
3239 | portp->brdnr = brdp->brdnr; | 3226 | portp->brdnr = brdp->brdnr; |
@@ -4610,14 +4597,13 @@ static stlibrd_t *stli_allocbrd(void) | |||
4610 | { | 4597 | { |
4611 | stlibrd_t *brdp; | 4598 | stlibrd_t *brdp; |
4612 | 4599 | ||
4613 | brdp = (stlibrd_t *) stli_memalloc(sizeof(stlibrd_t)); | 4600 | brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL); |
4614 | if (brdp == (stlibrd_t *) NULL) { | 4601 | if (!brdp) { |
4615 | printk(KERN_ERR "STALLION: failed to allocate memory " | 4602 | printk(KERN_ERR "STALLION: failed to allocate memory " |
4616 | "(size=%d)\n", sizeof(stlibrd_t)); | 4603 | "(size=%d)\n", sizeof(stlibrd_t)); |
4617 | return((stlibrd_t *) NULL); | 4604 | return NULL; |
4618 | } | 4605 | } |
4619 | 4606 | ||
4620 | memset(brdp, 0, sizeof(stlibrd_t)); | ||
4621 | brdp->magic = STLI_BOARDMAGIC; | 4607 | brdp->magic = STLI_BOARDMAGIC; |
4622 | return(brdp); | 4608 | return(brdp); |
4623 | } | 4609 | } |
@@ -5210,12 +5196,12 @@ int __init stli_init(void) | |||
5210 | /* | 5196 | /* |
5211 | * Allocate a temporary write buffer. | 5197 | * Allocate a temporary write buffer. |
5212 | */ | 5198 | */ |
5213 | stli_tmpwritebuf = (char *) stli_memalloc(STLI_TXBUFSIZE); | 5199 | stli_tmpwritebuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL); |
5214 | if (stli_tmpwritebuf == (char *) NULL) | 5200 | if (!stli_tmpwritebuf) |
5215 | printk(KERN_ERR "STALLION: failed to allocate memory " | 5201 | printk(KERN_ERR "STALLION: failed to allocate memory " |
5216 | "(size=%d)\n", STLI_TXBUFSIZE); | 5202 | "(size=%d)\n", STLI_TXBUFSIZE); |
5217 | stli_txcookbuf = stli_memalloc(STLI_TXBUFSIZE); | 5203 | stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL); |
5218 | if (stli_txcookbuf == (char *) NULL) | 5204 | if (!stli_txcookbuf) |
5219 | printk(KERN_ERR "STALLION: failed to allocate memory " | 5205 | printk(KERN_ERR "STALLION: failed to allocate memory " |
5220 | "(size=%d)\n", STLI_TXBUFSIZE); | 5206 | "(size=%d)\n", STLI_TXBUFSIZE); |
5221 | 5207 | ||
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c index 3f5d6077f39c..a9c5a7230f89 100644 --- a/drivers/char/stallion.c +++ b/drivers/char/stallion.c | |||
@@ -504,7 +504,6 @@ static int stl_echmcaintr(stlbrd_t *brdp); | |||
504 | static int stl_echpciintr(stlbrd_t *brdp); | 504 | static int stl_echpciintr(stlbrd_t *brdp); |
505 | static int stl_echpci64intr(stlbrd_t *brdp); | 505 | static int stl_echpci64intr(stlbrd_t *brdp); |
506 | static void stl_offintr(void *private); | 506 | static void stl_offintr(void *private); |
507 | static void *stl_memalloc(int len); | ||
508 | static stlbrd_t *stl_allocbrd(void); | 507 | static stlbrd_t *stl_allocbrd(void); |
509 | static stlport_t *stl_getport(int brdnr, int panelnr, int portnr); | 508 | static stlport_t *stl_getport(int brdnr, int panelnr, int portnr); |
510 | 509 | ||
@@ -940,17 +939,6 @@ static int stl_parsebrd(stlconf_t *confp, char **argp) | |||
940 | /*****************************************************************************/ | 939 | /*****************************************************************************/ |
941 | 940 | ||
942 | /* | 941 | /* |
943 | * Local driver kernel memory allocation routine. | ||
944 | */ | ||
945 | |||
946 | static void *stl_memalloc(int len) | ||
947 | { | ||
948 | return (void *) kmalloc(len, GFP_KERNEL); | ||
949 | } | ||
950 | |||
951 | /*****************************************************************************/ | ||
952 | |||
953 | /* | ||
954 | * Allocate a new board structure. Fill out the basic info in it. | 942 | * Allocate a new board structure. Fill out the basic info in it. |
955 | */ | 943 | */ |
956 | 944 | ||
@@ -958,14 +946,13 @@ static stlbrd_t *stl_allocbrd(void) | |||
958 | { | 946 | { |
959 | stlbrd_t *brdp; | 947 | stlbrd_t *brdp; |
960 | 948 | ||
961 | brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t)); | 949 | brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL); |
962 | if (brdp == (stlbrd_t *) NULL) { | 950 | if (!brdp) { |
963 | printk("STALLION: failed to allocate memory (size=%d)\n", | 951 | printk("STALLION: failed to allocate memory (size=%d)\n", |
964 | sizeof(stlbrd_t)); | 952 | sizeof(stlbrd_t)); |
965 | return (stlbrd_t *) NULL; | 953 | return NULL; |
966 | } | 954 | } |
967 | 955 | ||
968 | memset(brdp, 0, sizeof(stlbrd_t)); | ||
969 | brdp->magic = STL_BOARDMAGIC; | 956 | brdp->magic = STL_BOARDMAGIC; |
970 | return brdp; | 957 | return brdp; |
971 | } | 958 | } |
@@ -1017,9 +1004,9 @@ static int stl_open(struct tty_struct *tty, struct file *filp) | |||
1017 | portp->refcount++; | 1004 | portp->refcount++; |
1018 | 1005 | ||
1019 | if ((portp->flags & ASYNC_INITIALIZED) == 0) { | 1006 | if ((portp->flags & ASYNC_INITIALIZED) == 0) { |
1020 | if (portp->tx.buf == (char *) NULL) { | 1007 | if (!portp->tx.buf) { |
1021 | portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE); | 1008 | portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL); |
1022 | if (portp->tx.buf == (char *) NULL) | 1009 | if (!portp->tx.buf) |
1023 | return -ENOMEM; | 1010 | return -ENOMEM; |
1024 | portp->tx.head = portp->tx.buf; | 1011 | portp->tx.head = portp->tx.buf; |
1025 | portp->tx.tail = portp->tx.buf; | 1012 | portp->tx.tail = portp->tx.buf; |
@@ -2178,13 +2165,12 @@ static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp) | |||
2178 | * each ports data structures. | 2165 | * each ports data structures. |
2179 | */ | 2166 | */ |
2180 | for (i = 0; (i < panelp->nrports); i++) { | 2167 | for (i = 0; (i < panelp->nrports); i++) { |
2181 | portp = (stlport_t *) stl_memalloc(sizeof(stlport_t)); | 2168 | portp = kzalloc(sizeof(stlport_t), GFP_KERNEL); |
2182 | if (portp == (stlport_t *) NULL) { | 2169 | if (!portp) { |
2183 | printk("STALLION: failed to allocate memory " | 2170 | printk("STALLION: failed to allocate memory " |
2184 | "(size=%d)\n", sizeof(stlport_t)); | 2171 | "(size=%d)\n", sizeof(stlport_t)); |
2185 | break; | 2172 | break; |
2186 | } | 2173 | } |
2187 | memset(portp, 0, sizeof(stlport_t)); | ||
2188 | 2174 | ||
2189 | portp->magic = STL_PORTMAGIC; | 2175 | portp->magic = STL_PORTMAGIC; |
2190 | portp->portnr = i; | 2176 | portp->portnr = i; |
@@ -2315,13 +2301,12 @@ static inline int stl_initeio(stlbrd_t *brdp) | |||
2315 | * can complete the setup. | 2301 | * can complete the setup. |
2316 | */ | 2302 | */ |
2317 | 2303 | ||
2318 | panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t)); | 2304 | panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL); |
2319 | if (panelp == (stlpanel_t *) NULL) { | 2305 | if (!panelp) { |
2320 | printk(KERN_WARNING "STALLION: failed to allocate memory " | 2306 | printk(KERN_WARNING "STALLION: failed to allocate memory " |
2321 | "(size=%d)\n", sizeof(stlpanel_t)); | 2307 | "(size=%d)\n", sizeof(stlpanel_t)); |
2322 | return(-ENOMEM); | 2308 | return -ENOMEM; |
2323 | } | 2309 | } |
2324 | memset(panelp, 0, sizeof(stlpanel_t)); | ||
2325 | 2310 | ||
2326 | panelp->magic = STL_PANELMAGIC; | 2311 | panelp->magic = STL_PANELMAGIC; |
2327 | panelp->brdnr = brdp->brdnr; | 2312 | panelp->brdnr = brdp->brdnr; |
@@ -2490,13 +2475,12 @@ static inline int stl_initech(stlbrd_t *brdp) | |||
2490 | status = inb(ioaddr + ECH_PNLSTATUS); | 2475 | status = inb(ioaddr + ECH_PNLSTATUS); |
2491 | if ((status & ECH_PNLIDMASK) != nxtid) | 2476 | if ((status & ECH_PNLIDMASK) != nxtid) |
2492 | break; | 2477 | break; |
2493 | panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t)); | 2478 | panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL); |
2494 | if (panelp == (stlpanel_t *) NULL) { | 2479 | if (!panelp) { |
2495 | printk("STALLION: failed to allocate memory " | 2480 | printk("STALLION: failed to allocate memory " |
2496 | "(size=%d)\n", sizeof(stlpanel_t)); | 2481 | "(size=%d)\n", sizeof(stlpanel_t)); |
2497 | break; | 2482 | break; |
2498 | } | 2483 | } |
2499 | memset(panelp, 0, sizeof(stlpanel_t)); | ||
2500 | panelp->magic = STL_PANELMAGIC; | 2484 | panelp->magic = STL_PANELMAGIC; |
2501 | panelp->brdnr = brdp->brdnr; | 2485 | panelp->brdnr = brdp->brdnr; |
2502 | panelp->panelnr = panelnr; | 2486 | panelp->panelnr = panelnr; |
@@ -3074,8 +3058,8 @@ static int __init stl_init(void) | |||
3074 | /* | 3058 | /* |
3075 | * Allocate a temporary write buffer. | 3059 | * Allocate a temporary write buffer. |
3076 | */ | 3060 | */ |
3077 | stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE); | 3061 | stl_tmpwritebuf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL); |
3078 | if (stl_tmpwritebuf == (char *) NULL) | 3062 | if (!stl_tmpwritebuf) |
3079 | printk("STALLION: failed to allocate memory (size=%d)\n", | 3063 | printk("STALLION: failed to allocate memory (size=%d)\n", |
3080 | STL_TXBUFSIZE); | 3064 | STL_TXBUFSIZE); |
3081 | 3065 | ||