adc: atomic allocate memory in spin_lock_irqsave
authorkfx <kfx@rock-chips.com>
Mon, 23 Apr 2012 04:51:24 +0000 (12:51 +0800)
committerkfx <kfx@rock-chips.com>
Mon, 23 Apr 2012 04:51:24 +0000 (12:51 +0800)
drivers/adc/core.c

index 0c439b987bc54c291ca246840c36db29ce864e01..4dba47194588015df361b458bd99e173c87b6726 100755 (executable)
@@ -98,7 +98,7 @@ static int adc_request_add(struct adc_host *adc, struct adc_client *client)
                 if(req->client->index == client->index)
                         return 0;
         }
-        req = kzalloc(sizeof(struct adc_request), GFP_KERNEL);
+        req = kzalloc(sizeof(struct adc_request), GFP_ATOMIC);
 
         if(!req)
                 return -ENOMEM;
@@ -129,7 +129,7 @@ void adc_core_irq_handle(struct adc_host *adc)
 
 int adc_host_read(struct adc_client *client, enum read_type type)
 {
-        int tmo;
+        int tmo, ret = 0;
        unsigned long flags;
         struct adc_host *adc = NULL;
 
@@ -144,7 +144,12 @@ int adc_host_read(struct adc_client *client, enum read_type type)
        }
 
        spin_lock_irqsave(&adc->lock, flags);
-        adc_request_add(adc, client);
+        ret = adc_request_add(adc, client);
+        if(ret < 0){
+                spin_unlock_irqrestore(&adc->lock, flags);
+                dev_err(adc->dev, "No memory for req\n");
+                return ret;
+        }
         client->is_finished = 0;
        spin_unlock_irqrestore(&adc->lock, flags);