[PATCH] InfiniBand: remove unsafe use of in_atomic()

From: Roland Dreier
Date: Tue Mar 15 2005 - 15:40:38 EST


Using in_atomic() to decide between GFP_KERNEL and GFP_ATOMIC is not
safe (it doesn't work if CONFIG_PREEMPT=n). Change to just always
allocating with GFP_ATOMIC, since we don't know if we can sleep or not.

Signed-off-by: Roland Dreier <roland@xxxxxxxxxxx>


--- linux-export.orig/drivers/infiniband/core/mad.c 2005-03-15 12:23:32.640868259 -0800
+++ linux-export/drivers/infiniband/core/mad.c 2005-03-15 12:26:56.311553460 -0800
@@ -646,7 +646,7 @@
struct ib_smp *smp,
struct ib_send_wr *send_wr)
{
- int ret, alloc_flags, solicited;
+ int ret, solicited;
unsigned long flags;
struct ib_mad_local_private *local;
struct ib_mad_private *mad_priv;
@@ -666,11 +666,7 @@
if (!ret || !device->process_mad)
goto out;

- if (in_atomic() || irqs_disabled())
- alloc_flags = GFP_ATOMIC;
- else
- alloc_flags = GFP_KERNEL;
- local = kmalloc(sizeof *local, alloc_flags);
+ local = kmalloc(sizeof *local, GFP_ATOMIC);
if (!local) {
ret = -ENOMEM;
printk(KERN_ERR PFX "No memory for ib_mad_local_private\n");
@@ -678,7 +674,7 @@
}
local->mad_priv = NULL;
local->recv_mad_agent = NULL;
- mad_priv = kmem_cache_alloc(ib_mad_cache, alloc_flags);
+ mad_priv = kmem_cache_alloc(ib_mad_cache, GFP_ATOMIC);
if (!mad_priv) {
ret = -ENOMEM;
printk(KERN_ERR PFX "No memory for local response MAD\n");
@@ -860,9 +856,7 @@
}

/* Allocate MAD send WR tracking structure */
- mad_send_wr = kmalloc(sizeof *mad_send_wr,
- (in_atomic() || irqs_disabled()) ?
- GFP_ATOMIC : GFP_KERNEL);
+ mad_send_wr = kmalloc(sizeof *mad_send_wr, GFP_ATOMIC);
if (!mad_send_wr) {
printk(KERN_ERR PFX "No memory for "
"ib_mad_send_wr_private\n");
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/