[openib-general] [PATCH] InfiniBand: remove unsafe use of in_atomic()
Roland Dreier
roland at topspin.com
Tue Mar 15 12:27:58 PST 2005
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 at topspin.com>
--- 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");
More information about the general
mailing list