wl1251_spi_wake memory leak?
Subsystems (5)
I was working on a patch to the crc7 code (basically, it simplifies both the CRC code *and* all callers if the CRC is computed left-justified) when I noticed that wl1251_spi_wake and wl1271_spi_init are *almost* identical functions.
Except that wl1271_spi_init kfree()s the cmd buffer before returning (leading to the question of why it's not stack allocated), while wl1251_spi_wake does not.
I didn't trace the code to see what spi_message_add_tail does with the buffer, but it seems that *one* of the two functions must have a bug.
Would someone like to suggest the correct fix? My instincts are to factor out the common code, but that's a bit more invasive than a drive-by patch should be.
My patch in progress is appended, FWIW. I was cleaning up code surrounding calls to crc7() when I hit the puzzle.
Thank you!
drivers/mmc/host/mmc_spi.c +1 -1
@@ -470,7 +470,7 @@ mmc_spi_command_send(struct mmc_spi_host *host, *cp++ = (u8)(arg >>16 ); *cp++ = (u8)(arg >>8 ); *cp++ = (u8 )arg; - *cp++ = (crc7 (0 , &data->status[1 ],5 ) <<1 ) |0x01 ; + *cp++ =crc7_be (0 , &data->status[1 ],5 ) |0x01 ;/* Then, read up to 13 bytes (while writing all-ones): * - N(CR) (== 1..8) bytes of all-ones
drivers/net/wireless/wl1251/acx.c +0 -1
@@ -2,7 +2,6 @@#include <linux/module.h> #include <linux/slab.h> -#include <linux/crc7.h> #include "wl1251.h" #include "reg.h"
drivers/net/wireless/wl1251/cmd.c +0 -1
@@ -2,7 +2,6 @@#include <linux/module.h> #include <linux/slab.h> -#include <linux/crc7.h> #include "wl1251.h" #include "reg.h"
drivers/net/wireless/wl1251/spi.c +6 -9
@@ -86,7 +86,6 @@ static void wl1251_spi_wake(struct wl1251 *wl)return ; } -memset (crc,0 ,sizeof (crc));memset (&t,0 ,sizeof (t));spi_message_init (&m);
@@ -99,25 +98,23 @@ static void wl1251_spi_wake(struct wl1251 *wl) cmd[1 ] =WSPI_INIT_CMD_START |WSPI_INIT_CMD_TX ; cmd[0 ] =0 ; cmd[7 ] =0 ; - cmd[6 ] |=HW_ACCESS_WSPI_INIT_CMD_MASK <<3 ; - cmd[6 ] |=HW_ACCESS_WSPI_FIXED_BUSY_LEN &WSPI_INIT_CMD_FIXEDBUSY_LEN ; + cmd[6 ] =HW_ACCESS_WSPI_INIT_CMD_MASK <<3 | +HW_ACCESS_WSPI_FIXED_BUSY_LEN &WSPI_INIT_CMD_FIXEDBUSY_LEN ; + cmd[5 ] =WSPI_INIT_CMD_IOD |WSPI_INIT_CMD_IP |WSPI_INIT_CMD_CS + |WSPI_INIT_CMD_WSPI |WSPI_INIT_CMD_WS ;if (HW_ACCESS_WSPI_FIXED_BUSY_LEN ==0 ) - cmd[5 ] |=WSPI_INIT_CMD_DIS_FIXEDBUSY ; + cmd[5 ] |=WSPI_INIT_CMD_DIS_FIXEDBUSY ;else cmd[5 ] |=WSPI_INIT_CMD_EN_FIXEDBUSY ; - cmd[5 ] |=WSPI_INIT_CMD_IOD |WSPI_INIT_CMD_IP |WSPI_INIT_CMD_CS - |WSPI_INIT_CMD_WSPI |WSPI_INIT_CMD_WS ; - crc[0 ] = cmd[1 ]; crc[1 ] = cmd[0 ]; crc[2 ] = cmd[7 ]; crc[3 ] = cmd[6 ]; crc[4 ] = cmd[5 ]; - cmd[4 ] |=crc7 (0 , crc,WSPI_INIT_CMD_CRC_LEN ) <<1 ; - cmd[4 ] |=WSPI_INIT_CMD_END ; + cmd[4 ] =crc7_be (0 , crc,WSPI_INIT_CMD_CRC_LEN ) |WSPI_INIT_CMD_END ; t.tx_buf = cmd; t.len =WSPI_INIT_CMD_LEN ;
drivers/net/wireless/wl12xx/acx.c +0 -1
@@ -25,7 +25,6 @@#include <linux/module.h> #include <linux/platform_device.h> -#include <linux/crc7.h> #include <linux/spi/spi.h> #include <linux/slab.h>
drivers/net/wireless/wl12xx/cmd.c +0 -1
@@ -23,7 +23,6 @@#include <linux/module.h> #include <linux/platform_device.h> -#include <linux/crc7.h> #include <linux/spi/spi.h> #include <linux/etherdevice.h> #include <linux/ieee80211.h>
drivers/net/wireless/wl12xx/io.c +0 -1
@@ -23,7 +23,6 @@#include <linux/module.h> #include <linux/platform_device.h> -#include <linux/crc7.h> #include <linux/spi/spi.h> #include "wl12xx.h"
drivers/net/wireless/wl12xx/sdio.c +0 -1
@@ -23,7 +23,6 @@#include <linux/irq.h> #include <linux/module.h> -#include <linux/crc7.h> #include <linux/vmalloc.h> #include <linux/mmc/sdio_func.h> #include <linux/mmc/sdio_ids.h>
drivers/net/wireless/wl12xx/sdio_test.c +0 -1
@@ -25,7 +25,6 @@#include <linux/irq.h> #include <linux/module.h> -#include <linux/crc7.h> #include <linux/vmalloc.h> #include <linux/mmc/sdio_func.h> #include <linux/mmc/sdio_ids.h>
drivers/net/wireless/wl12xx/spi.c +6 -9
@@ -126,7 +126,6 @@ static void wl1271_spi_init(struct wl1271 *wl)return ; } -memset (crc,0 ,sizeof (crc));memset (&t,0 ,sizeof (t));spi_message_init (&m);
@@ -139,25 +138,23 @@ static void wl1271_spi_init(struct wl1271 *wl) cmd[1 ] =WSPI_INIT_CMD_START |WSPI_INIT_CMD_TX ; cmd[0 ] =0 ; cmd[7 ] =0 ; - cmd[6 ] |=HW_ACCESS_WSPI_INIT_CMD_MASK <<3 ; - cmd[6 ] |=HW_ACCESS_WSPI_FIXED_BUSY_LEN &WSPI_INIT_CMD_FIXEDBUSY_LEN ; + cmd[6 ] =HW_ACCESS_WSPI_INIT_CMD_MASK <<3 | +HW_ACCESS_WSPI_FIXED_BUSY_LEN &WSPI_INIT_CMD_FIXEDBUSY_LEN ; + cmd[5 ] =WSPI_INIT_CMD_IOD |WSPI_INIT_CMD_IP |WSPI_INIT_CMD_CS + |WSPI_INIT_CMD_WSPI |WSPI_INIT_CMD_WS ;if (HW_ACCESS_WSPI_FIXED_BUSY_LEN ==0 ) - cmd[5 ] |=WSPI_INIT_CMD_DIS_FIXEDBUSY ; + cmd[5 ] |=WSPI_INIT_CMD_DIS_FIXEDBUSY ;else cmd[5 ] |=WSPI_INIT_CMD_EN_FIXEDBUSY ; - cmd[5 ] |=WSPI_INIT_CMD_IOD |WSPI_INIT_CMD_IP |WSPI_INIT_CMD_CS - |WSPI_INIT_CMD_WSPI |WSPI_INIT_CMD_WS ; - crc[0 ] = cmd[1 ]; crc[1 ] = cmd[0 ]; crc[2 ] = cmd[7 ]; crc[3 ] = cmd[6 ]; crc[4 ] = cmd[5 ]; - cmd[4 ] |=crc7 (0 , crc,WSPI_INIT_CMD_CRC_LEN ) <<1 ; - cmd[4 ] |=WSPI_INIT_CMD_END ; + cmd[4 ] =crc7_be (0 , crc,WSPI_INIT_CMD_CRC_LEN ) |WSPI_INIT_CMD_END ; t.tx_buf = cmd; t.len =WSPI_INIT_CMD_LEN ;
include/linux/crc7.h +7 -3
@@ -4,11 +4,15 @@extern const u8 crc7_syndrome_table[256 ]; -static inline u8 crc7_byte (u8 crc,u8 data) +/* +* The CRC is maintained left-justified, in the most significant 7 bits +* of the crc variable. Thus the _be (big-endian) suffix. +*/ +static inline u8 crc7_byte_be (u8 crc,u8 data) { -return crc7_syndrome_table[(crc <<1 ) ^ data]; +return crc7_syndrome_table[crc ^ data]; } -extern u8 crc7 (u8 crc,const u8 *buffer,size_t len); +extern u8 crc7_be (u8 crc,const u8 *buffer,size_t len);#endif
lib/crc7.c +35 -35
86 lines not on this page · raw message