staging: ft1000: ft1000-usb: ft1000_hw.c: Fix a potential memory leak.
authorRickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Mon, 29 Dec 2014 12:41:33 +0000 (13:41 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 17 Jan 2015 23:22:31 +0000 (15:22 -0800)
Avoid allocate memory if we will exit the function.

Was found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/ft1000/ft1000-usb/ft1000_hw.c

index d12cfc9aa32a6c489d9dc7d0adf6e562eba9a5cc..f0ac438384617f81b9d0d067ef64a74b03808f38 100644 (file)
@@ -332,15 +332,15 @@ int card_send_command(struct ft1000_usb *ft1000dev, void *ptempbuffer,
 
        pr_debug("enter card_send_command... size=%d\n", size);
 
+       ret = ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
+       if (ret)
+               return ret;
+
        commandbuf = kmalloc(size + 2, GFP_KERNEL);
        if (!commandbuf)
                return -ENOMEM;
        memcpy((void *)commandbuf + 2, (void *)ptempbuffer, size);
 
-       ret = ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
-       if (ret)
-               return ret;
-
        if (temp & 0x0100)
                usleep_range(900, 1100);