[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>
This commit is contained in:
parent
993dfa8776
commit
b0b4ed728c
|
@ -706,7 +706,6 @@ static int stli_portcmdstats(stliport_t *portp);
|
||||||
static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp);
|
static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp);
|
||||||
static int stli_getportstruct(stliport_t __user *arg);
|
static int stli_getportstruct(stliport_t __user *arg);
|
||||||
static int stli_getbrdstruct(stlibrd_t __user *arg);
|
static int stli_getbrdstruct(stlibrd_t __user *arg);
|
||||||
static void *stli_memalloc(int len);
|
|
||||||
static stlibrd_t *stli_allocbrd(void);
|
static stlibrd_t *stli_allocbrd(void);
|
||||||
|
|
||||||
static void stli_ecpinit(stlibrd_t *brdp);
|
static void stli_ecpinit(stlibrd_t *brdp);
|
||||||
|
@ -997,17 +996,6 @@ static int stli_parsebrd(stlconf_t *confp, char **argp)
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
/*
|
|
||||||
* Local driver kernel malloc routine.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void *stli_memalloc(int len)
|
|
||||||
{
|
|
||||||
return((void *) kmalloc(len, GFP_KERNEL));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
static int stli_open(struct tty_struct *tty, struct file *filp)
|
static int stli_open(struct tty_struct *tty, struct file *filp)
|
||||||
{
|
{
|
||||||
stlibrd_t *brdp;
|
stlibrd_t *brdp;
|
||||||
|
@ -3227,13 +3215,12 @@ static int stli_initports(stlibrd_t *brdp)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
|
for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
|
||||||
portp = (stliport_t *) stli_memalloc(sizeof(stliport_t));
|
portp = kzalloc(sizeof(stliport_t), GFP_KERNEL);
|
||||||
if (portp == (stliport_t *) NULL) {
|
if (!portp) {
|
||||||
printk("STALLION: failed to allocate port structure\n");
|
printk("STALLION: failed to allocate port structure\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(portp, 0, sizeof(stliport_t));
|
|
||||||
portp->magic = STLI_PORTMAGIC;
|
portp->magic = STLI_PORTMAGIC;
|
||||||
portp->portnr = i;
|
portp->portnr = i;
|
||||||
portp->brdnr = brdp->brdnr;
|
portp->brdnr = brdp->brdnr;
|
||||||
|
@ -4610,14 +4597,13 @@ static stlibrd_t *stli_allocbrd(void)
|
||||||
{
|
{
|
||||||
stlibrd_t *brdp;
|
stlibrd_t *brdp;
|
||||||
|
|
||||||
brdp = (stlibrd_t *) stli_memalloc(sizeof(stlibrd_t));
|
brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL);
|
||||||
if (brdp == (stlibrd_t *) NULL) {
|
if (!brdp) {
|
||||||
printk(KERN_ERR "STALLION: failed to allocate memory "
|
printk(KERN_ERR "STALLION: failed to allocate memory "
|
||||||
"(size=%d)\n", sizeof(stlibrd_t));
|
"(size=%d)\n", sizeof(stlibrd_t));
|
||||||
return((stlibrd_t *) NULL);
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(brdp, 0, sizeof(stlibrd_t));
|
|
||||||
brdp->magic = STLI_BOARDMAGIC;
|
brdp->magic = STLI_BOARDMAGIC;
|
||||||
return(brdp);
|
return(brdp);
|
||||||
}
|
}
|
||||||
|
@ -5210,12 +5196,12 @@ int __init stli_init(void)
|
||||||
/*
|
/*
|
||||||
* Allocate a temporary write buffer.
|
* Allocate a temporary write buffer.
|
||||||
*/
|
*/
|
||||||
stli_tmpwritebuf = (char *) stli_memalloc(STLI_TXBUFSIZE);
|
stli_tmpwritebuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
|
||||||
if (stli_tmpwritebuf == (char *) NULL)
|
if (!stli_tmpwritebuf)
|
||||||
printk(KERN_ERR "STALLION: failed to allocate memory "
|
printk(KERN_ERR "STALLION: failed to allocate memory "
|
||||||
"(size=%d)\n", STLI_TXBUFSIZE);
|
"(size=%d)\n", STLI_TXBUFSIZE);
|
||||||
stli_txcookbuf = stli_memalloc(STLI_TXBUFSIZE);
|
stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
|
||||||
if (stli_txcookbuf == (char *) NULL)
|
if (!stli_txcookbuf)
|
||||||
printk(KERN_ERR "STALLION: failed to allocate memory "
|
printk(KERN_ERR "STALLION: failed to allocate memory "
|
||||||
"(size=%d)\n", STLI_TXBUFSIZE);
|
"(size=%d)\n", STLI_TXBUFSIZE);
|
||||||
|
|
||||||
|
|
|
@ -504,7 +504,6 @@ static int stl_echmcaintr(stlbrd_t *brdp);
|
||||||
static int stl_echpciintr(stlbrd_t *brdp);
|
static int stl_echpciintr(stlbrd_t *brdp);
|
||||||
static int stl_echpci64intr(stlbrd_t *brdp);
|
static int stl_echpci64intr(stlbrd_t *brdp);
|
||||||
static void stl_offintr(void *private);
|
static void stl_offintr(void *private);
|
||||||
static void *stl_memalloc(int len);
|
|
||||||
static stlbrd_t *stl_allocbrd(void);
|
static stlbrd_t *stl_allocbrd(void);
|
||||||
static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
|
static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
|
||||||
|
|
||||||
|
@ -939,17 +938,6 @@ static int stl_parsebrd(stlconf_t *confp, char **argp)
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
/*
|
|
||||||
* Local driver kernel memory allocation routine.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void *stl_memalloc(int len)
|
|
||||||
{
|
|
||||||
return (void *) kmalloc(len, GFP_KERNEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate a new board structure. Fill out the basic info in it.
|
* Allocate a new board structure. Fill out the basic info in it.
|
||||||
*/
|
*/
|
||||||
|
@ -958,14 +946,13 @@ static stlbrd_t *stl_allocbrd(void)
|
||||||
{
|
{
|
||||||
stlbrd_t *brdp;
|
stlbrd_t *brdp;
|
||||||
|
|
||||||
brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
|
brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL);
|
||||||
if (brdp == (stlbrd_t *) NULL) {
|
if (!brdp) {
|
||||||
printk("STALLION: failed to allocate memory (size=%d)\n",
|
printk("STALLION: failed to allocate memory (size=%d)\n",
|
||||||
sizeof(stlbrd_t));
|
sizeof(stlbrd_t));
|
||||||
return (stlbrd_t *) NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(brdp, 0, sizeof(stlbrd_t));
|
|
||||||
brdp->magic = STL_BOARDMAGIC;
|
brdp->magic = STL_BOARDMAGIC;
|
||||||
return brdp;
|
return brdp;
|
||||||
}
|
}
|
||||||
|
@ -1017,9 +1004,9 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
|
||||||
portp->refcount++;
|
portp->refcount++;
|
||||||
|
|
||||||
if ((portp->flags & ASYNC_INITIALIZED) == 0) {
|
if ((portp->flags & ASYNC_INITIALIZED) == 0) {
|
||||||
if (portp->tx.buf == (char *) NULL) {
|
if (!portp->tx.buf) {
|
||||||
portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE);
|
portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
|
||||||
if (portp->tx.buf == (char *) NULL)
|
if (!portp->tx.buf)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
portp->tx.head = portp->tx.buf;
|
portp->tx.head = portp->tx.buf;
|
||||||
portp->tx.tail = portp->tx.buf;
|
portp->tx.tail = portp->tx.buf;
|
||||||
|
@ -2178,13 +2165,12 @@ static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
|
||||||
* each ports data structures.
|
* each ports data structures.
|
||||||
*/
|
*/
|
||||||
for (i = 0; (i < panelp->nrports); i++) {
|
for (i = 0; (i < panelp->nrports); i++) {
|
||||||
portp = (stlport_t *) stl_memalloc(sizeof(stlport_t));
|
portp = kzalloc(sizeof(stlport_t), GFP_KERNEL);
|
||||||
if (portp == (stlport_t *) NULL) {
|
if (!portp) {
|
||||||
printk("STALLION: failed to allocate memory "
|
printk("STALLION: failed to allocate memory "
|
||||||
"(size=%d)\n", sizeof(stlport_t));
|
"(size=%d)\n", sizeof(stlport_t));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
memset(portp, 0, sizeof(stlport_t));
|
|
||||||
|
|
||||||
portp->magic = STL_PORTMAGIC;
|
portp->magic = STL_PORTMAGIC;
|
||||||
portp->portnr = i;
|
portp->portnr = i;
|
||||||
|
@ -2315,13 +2301,12 @@ static inline int stl_initeio(stlbrd_t *brdp)
|
||||||
* can complete the setup.
|
* can complete the setup.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
|
panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
|
||||||
if (panelp == (stlpanel_t *) NULL) {
|
if (!panelp) {
|
||||||
printk(KERN_WARNING "STALLION: failed to allocate memory "
|
printk(KERN_WARNING "STALLION: failed to allocate memory "
|
||||||
"(size=%d)\n", sizeof(stlpanel_t));
|
"(size=%d)\n", sizeof(stlpanel_t));
|
||||||
return(-ENOMEM);
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
memset(panelp, 0, sizeof(stlpanel_t));
|
|
||||||
|
|
||||||
panelp->magic = STL_PANELMAGIC;
|
panelp->magic = STL_PANELMAGIC;
|
||||||
panelp->brdnr = brdp->brdnr;
|
panelp->brdnr = brdp->brdnr;
|
||||||
|
@ -2490,13 +2475,12 @@ static inline int stl_initech(stlbrd_t *brdp)
|
||||||
status = inb(ioaddr + ECH_PNLSTATUS);
|
status = inb(ioaddr + ECH_PNLSTATUS);
|
||||||
if ((status & ECH_PNLIDMASK) != nxtid)
|
if ((status & ECH_PNLIDMASK) != nxtid)
|
||||||
break;
|
break;
|
||||||
panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
|
panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
|
||||||
if (panelp == (stlpanel_t *) NULL) {
|
if (!panelp) {
|
||||||
printk("STALLION: failed to allocate memory "
|
printk("STALLION: failed to allocate memory "
|
||||||
"(size=%d)\n", sizeof(stlpanel_t));
|
"(size=%d)\n", sizeof(stlpanel_t));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
memset(panelp, 0, sizeof(stlpanel_t));
|
|
||||||
panelp->magic = STL_PANELMAGIC;
|
panelp->magic = STL_PANELMAGIC;
|
||||||
panelp->brdnr = brdp->brdnr;
|
panelp->brdnr = brdp->brdnr;
|
||||||
panelp->panelnr = panelnr;
|
panelp->panelnr = panelnr;
|
||||||
|
@ -3074,8 +3058,8 @@ static int __init stl_init(void)
|
||||||
/*
|
/*
|
||||||
* Allocate a temporary write buffer.
|
* Allocate a temporary write buffer.
|
||||||
*/
|
*/
|
||||||
stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
|
stl_tmpwritebuf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
|
||||||
if (stl_tmpwritebuf == (char *) NULL)
|
if (!stl_tmpwritebuf)
|
||||||
printk("STALLION: failed to allocate memory (size=%d)\n",
|
printk("STALLION: failed to allocate memory (size=%d)\n",
|
||||||
STL_TXBUFSIZE);
|
STL_TXBUFSIZE);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue