From: Jim C. <jim...@gm...> - 2012-04-09 08:50:02
|
Caller of eeprom readers formerly did the kmalloc, and "hoped it was enough". Now doing malloc where size is known, returning pointer and length via *arg. Adjust protos accordingly. Downside is that mallocs are freed by caller, which adds a modest action-at-a-distance complexity. Later look for sparse macros to document/enforce this. Cleanups: rename buf2 to p, its used like a pointer. Change for(), seq_putc in body not reinit is more conventional. Drop useless length assignment, callee sets it. Signed-off-by: Jim Cromie <jim...@gm...> --- acx_func.h | 4 ++-- common.c | 20 ++++++-------------- mem.c | 10 ++++++---- pci.c | 10 ++++++---- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/acx_func.h b/acx_func.h index d12cb5d..22a614a 100644 --- a/acx_func.h +++ b/acx_func.h @@ -549,7 +549,7 @@ int acxpci_reset_dev(acx_device_t * adev); // Proc, Debug int acxpci_proc_diag_output(struct seq_file *file, acx_device_t *adev); -int acxpci_proc_eeprom_output(char *buf, acx_device_t * adev); +char *acxpci_proc_eeprom_output(int *len, acx_device_t * adev); // Rx Path @@ -607,7 +607,7 @@ int acxmem_reset_dev(acx_device_t *adev); // Proc, Debug int acxmem_proc_diag_output(struct seq_file *file, acx_device_t *adev); -int acxmem_proc_eeprom_output(char *buf, acx_device_t *adev); +char *acxmem_proc_eeprom_output(int *len, acx_device_t *adev); // Rx Path diff --git a/common.c b/common.c index ff422e0..afb57a3 100644 --- a/common.c +++ b/common.c @@ -4580,34 +4580,26 @@ static int acx_proc_show_eeprom(struct seq_file *file, void *v) acx_device_t *adev = (acx_device_t *) file->private; int length; - char *buf, *buf2; - // OW Hopefully enough - const int buf_size = 1024*64; + char *buf, *p; FN_ENTER; acx_sem_lock(adev); - buf = kmalloc(buf_size, GFP_KERNEL); - - /* fill buf */ - length = 0; if (IS_PCI(adev)) - length = acxpci_proc_eeprom_output(buf, adev); + buf = acxpci_proc_eeprom_output(&length, adev); else if (IS_MEM(adev)) - length = acxmem_proc_eeprom_output(buf, adev); + buf = acxmem_proc_eeprom_output(&length, adev); else goto out; - for (buf2 = buf; buf2 < buf + length; seq_putc(file, *(buf2++))) - ; + for (p = buf; p < buf + length; p++) + seq_putc(file, *p); - out: kfree(buf); - +out: acx_sem_unlock(adev); FN_EXIT0; return 0; - } static int acx_proc_show_phy(struct seq_file *file, void *v) diff --git a/mem.c b/mem.c index f5bfa30..6e66c74 100644 --- a/mem.c +++ b/mem.c @@ -181,7 +181,7 @@ static void acxmem_up(struct ieee80211_hw *hw); // Proc, Debug int acxmem_proc_diag_output(struct seq_file *file, acx_device_t *adev); -int acxmem_proc_eeprom_output(char *buf, acx_device_t *adev); +char *acxmem_proc_eeprom_output(int *len, acx_device_t *adev); // Rx Path static void acxmem_process_rxdesc(acx_device_t *adev); @@ -2888,21 +2888,23 @@ int acxmem_proc_diag_output(struct seq_file *file, acx_device_t *adev) { return 0; } -int acxmem_proc_eeprom_output(char *buf, acx_device_t *adev) { - char *p = buf; +char *acxmem_proc_eeprom_output(int *length, acx_device_t *adev) { + char *p, *buf; int i; acxmem_lock_flags; FN_ENTER; acxmem_lock(); + p = buf = kmalloc(0x400, GFP_KERNEL); for (i = 0; i < 0x400; i++) { acxmem_read_eeprom_byte(adev, i, p++); } + *length = i; acxmem_unlock(); FN_EXIT1(p - buf); - return p - buf; + return buf; } /* diff --git a/pci.c b/pci.c index e5bfca2..4d4d51d 100644 --- a/pci.c +++ b/pci.c @@ -126,7 +126,7 @@ static void acxpci_up(struct ieee80211_hw *hw); // Proc, Debug int acxpci_proc_diag_output(struct seq_file *file, acx_device_t *adev); -int acxpci_proc_eeprom_output(char *buf, acx_device_t * adev); +char *acxpci_proc_eeprom_output(int *len, acx_device_t * adev); // Rx Path static void acxpci_process_rxdesc(acx_device_t * adev); @@ -1940,19 +1940,21 @@ int acxpci_proc_diag_output(struct seq_file *file, acx_device_t *adev) return 0; } -int acxpci_proc_eeprom_output(char *buf, acx_device_t * adev) +char *acxpci_proc_eeprom_output(int *len, acx_device_t * adev) { - char *p = buf; int i; + char *p, *buf; FN_ENTER; + p = buf = kmalloc(0x400, GFP_KERNEL); for (i = 0; i < 0x400; i++) { acxpci_read_eeprom_byte(adev, i, p++); } + *len = i; FN_EXIT1(p - buf); - return p - buf; + return buf; } -- 1.7.8.1 |