Skip to contentSkip to conversation

qla2xxx: use memory_read_from_buffer()

PATCH In review [email protected] 3 participants 13 messages Jul 4, 2008

Subsystems (11)
VFS SCSI ACPI Framebuffer layer +7 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 14/16 qla2xxx: use memory_read_from_buffer()

From: Akinobu Mita <[email protected]>

---

 drivers/scsi/qla2xxx/qla_attr.c |   45 ++++++------------------------
 1 file changed, 10 insertions(+), 35 deletions(-)
drivers/scsi/qla2xxx/qla_attr.c renamed from drivers/scsi/qla2xxx/qla_attr.c~qla2xxx-use-memory_read_from_buffer +10 -35
diff -puN drivers/scsi/qla2xxx/qla_attr.c~qla2xxx-use-memory_read_from_buffer drivers/scsi/qla2xxx/qla_attr.c
@@ -8,6 +8,7 @@
 
 #include <linux/kthread.h>
 #include <linux/vmalloc.h>
+#include <linux/fs.h>
 
 static int qla24xx_vport_disable(struct fc_vport *, bool);
 
@@ -20,18 +21,12 @@ qla2x00_sysfs_read_fw_dump(struct kobjec
 {
 	struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
 	    struct device, kobj)));
-	char *rbuf = (char *)ha->fw_dump;
 
 	if (ha->fw_dump_reading == 0)
 		return 0;
-	if (off > ha->fw_dump_len)
-                return 0;
-	if (off + count > ha->fw_dump_len)
-		count = ha->fw_dump_len - off;
 
-	memcpy(buf, &rbuf[off], count);
-
-	return (count);
+	return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
+					ha->fw_dump_len);
 }
 
 static ssize_t
@@ -94,20 +89,13 @@ qla2x00_sysfs_read_nvram(struct kobject 
 {
 	struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
 	    struct device, kobj)));
-	int		size = ha->nvram_size;
-	char		*nvram_cache = ha->nvram;
 
-	if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
+	if (!capable(CAP_SYS_ADMIN))
 		return 0;
-	if (off + count > size) {
-		size -= off;
-		count = size;
-	}
 
 	/* Read NVRAM data from cache. */
-	memcpy(buf, &nvram_cache[off], count);
-
-	return count;
+	return memory_read_from_buffer(buf, count, &off, ha->nvram,
+					ha->nvram_size);
 }
 
 static ssize_t
@@ -175,14 +163,9 @@ qla2x00_sysfs_read_optrom(struct kobject
 
 	if (ha->optrom_state != QLA_SREADING)
 		return 0;
-	if (off > ha->optrom_region_size)
-		return 0;
-	if (off + count > ha->optrom_region_size)
-		count = ha->optrom_region_size - off;
 
-	memcpy(buf, &ha->optrom_buffer[off], count);
-
-	return count;
+	return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
+					ha->optrom_region_size);
 }
 
 static ssize_t
@@ -374,20 +357,12 @@ qla2x00_sysfs_read_vpd(struct kobject *k
 {
 	struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
 	    struct device, kobj)));
-	int           size = ha->vpd_size;
-	char          *vpd_cache = ha->vpd;
 
-	if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
+	if (!capable(CAP_SYS_ADMIN))
 		return 0;
-	if (off + count > size) {
-		size -= off;
-		count = size;
-	}
 
 	/* Read NVRAM data from cache. */
-	memcpy(buf, &vpd_cache[off], count);
-
-	return count;
+	return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
 }
 
 static ssize_t

_

maintainer
#1 lore raw
Quoted 17 lines · On Thu, 2008-07-03 at 23:47 -0700, [email protected] wrote:

From: Akinobu Mita <[email protected]>

---

 drivers/scsi/qla2xxx/qla_attr.c |   45 ++++++------------------------
 1 file changed, 10 insertions(+), 35 deletions(-)

diff -puN drivers/scsi/qla2xxx/qla_attr.c~qla2xxx-use-memory_read_from_buffer drivers/scsi/qla2xxx/qla_attr.c

drivers/scsi/qla2xxx/qla_attr.c line 11

Quoted 4 lines
drivers/scsi/qla2xxx/qla_attr.c renamed from drivers/scsi/qla2xxx/qla_attr.c~qla2xxx-use-memory_read_from_buffer +1 -0
@@ -8,6 +8,7 @@
 
 #include <linux/kthread.h>
 #include <linux/vmalloc.h>
+#include <linux/fs.h>

For such a micro optimisation, this is a pretty big price to pay.

Inclusion of linux/fs.h in a low level driver was always a danger signal usually it meant the driver was trying to access files or something at the very least it was a warning of a potential layering violation. Now you're trying to make it standard practice ... I really don't like that. Surely a function that does memory to memory copies belongs either in string.h with the rest of our memory copies ... or in another header that would be a usual include for the potential users.

James

#2 lore raw

PATCH 1/1 move memory_read_from_buffer() from fs.h to string.h

Quoted 9 lines · James Bottomley

For such a micro optimisation, this is a pretty big price to pay.

Inclusion of linux/fs.h in a low level driver was always a danger signal usually it meant the driver was trying to access files or something at the very least it was a warning of a potential layering violation. Now you're trying to make it standard practice ... I really don't like that. Surely a function that does memory to memory copies belongs either in string.h with the rest of our memory copies ... or in another header that would be a usual include for the potential users.

OK, I'll move it to linux/string.h

From: Akinobu Mita <[email protected]>
Subject: [PATCH] move memory_read_from_buffer() from fs.h to string.h

James Bottomley warns that inclusion of linux/fs.h in a low level driver was always a danger signal. This patch moves memory_read_from_buffer() from fs.h to string.h and fixes includes in existing memory_read_from_buffer() users.

Cc James Bottomley <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Zhang Rui <[email protected]>
Cc Bob Moore <[email protected]>
Cc Thomas Renninger <[email protected]>
Cc Len Brown <[email protected]>
---
 drivers/acpi/system.c       |    1 +
 drivers/zorro/zorro-sysfs.c |    1 -
 include/linux/fs.h          |    2 --
 include/linux/string.h      |    3 +++
 4 files changed, 4 insertions(+), 3 deletions(-)
include/linux/fs.h +0 -2
Index: 2.6-mm/include/linux/fs.h
===================================================================
@@ -2026,8 +2026,6 @@ extern void simple_release_fs(struct vfs
 
 extern ssize_t simple_read_from_buffer(void __user *to, size_t count,
 			loff_t *ppos, const void *from, size_t available);
-extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
-			const void *from, size_t available);
 
 #ifdef CONFIG_MIGRATION
 extern int buffer_migrate_page(struct address_space *,
include/linux/string.h +3 -0
Index: 2.6-mm/include/linux/string.h
===================================================================
@@ -111,5 +111,8 @@ extern void argv_free(char **argv);
 
 extern bool sysfs_streq(const char *s1, const char *s2);
 
+extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
+			const void *from, size_t available);
+
 #endif
 #endif /* _LINUX_STRING_H_ */
drivers/acpi/system.c +1 -0
Index: 2.6-mm/drivers/acpi/system.c
===================================================================
@@ -26,6 +26,7 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <linux/init.h>
+#include <linux/string.h>
 #include <asm/uaccess.h>
 
 #include <acpi/acpi_drivers.h>
drivers/zorro/zorro-sysfs.c +0 -1
Index: 2.6-mm/drivers/zorro/zorro-sysfs.c
===================================================================
@@ -15,7 +15,6 @@
 #include <linux/zorro.h>
 #include <linux/stat.h>
 #include <linux/string.h>
-#include <linux/fs.h>
 
 #include "zorro.h"
 
#3 lore raw

PATCH 1/1 fix s390-use-memory_read_from_buffer.patch

Now memory_read_from_buffer() belongs in string.h

Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Michael Holzheu <[email protected]>
---
 arch/s390/kernel/ipl.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kernel/ipl.c +1 -1
Index: 2.6-mm/arch/s390/kernel/ipl.c
===================================================================
@@ -14,7 +14,7 @@
 #include <linux/delay.h>
 #include <linux/reboot.h>
 #include <linux/ctype.h>
-#include <linux/fs.h>
+#include <linux/string.h>
 #include <asm/ipl.h>
 #include <asm/smp.h>
 #include <asm/setup.h>
#4 lore raw

PATCH 1/1 fix s390-cio-use-memory_read_from_buffer.patch

In reply to Akinobu Mita

Now memory_read_from_buffer() belongs in string.h

Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Peter Oberparleiter <[email protected]>
---
 drivers/s390/cio/chp.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/cio/chp.c +1 -1
Index: 2.6-mm/drivers/s390/cio/chp.c
===================================================================
@@ -15,7 +15,7 @@
 #include <linux/wait.h>
 #include <linux/mutex.h>
 #include <linux/errno.h>
-#include <linux/fs.h>
+#include <linux/string.h>
 #include <asm/chpid.h>
 #include <asm/sclp.h>
 
#5 lore raw

PATCH 1/1 fix qla2xxx-use-memory_read_from_buffer.patch

In reply to Akinobu Mita

Now memory_read_from_buffer() belongs in string.h

Cc Andrew Vasquez <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc Andrew Vasquez <[email protected]>
Cc Seokmann Ju <[email protected]>
---
 drivers/scsi/qla2xxx/qla_attr.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qla2xxx/qla_attr.c +1 -1
Index: 2.6-mm/drivers/scsi/qla2xxx/qla_attr.c
===================================================================
@@ -8,7 +8,7 @@
 
 #include <linux/kthread.h>
 #include <linux/vmalloc.h>
-#include <linux/fs.h>
+#include <linux/string.h>
 
 static int qla24xx_vport_disable(struct fc_vport *, bool);
 
#6 lore raw

PATCH 1/1 fix ipr-use-memory_read_from_buffer.patch

In reply to Akinobu Mita

Now memory_read_from_buffer() belongs in string.h

Cc Brian King <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/scsi/ipr.c |    1 +
 1 file changed, 1 insertion(+)
drivers/scsi/ipr.c +1 -0
Index: 2.6-mm/drivers/scsi/ipr.c
===================================================================
@@ -71,6 +71,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/libata.h>
+#include <linux/string.h>
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/processor.h>
maintainer
#7 lore raw

Re: [PATCH -mm] fix ipr-use-memory_read_from_buffer.patch

Quoted 14 lines · Akinobu Mita

Now memory_read_from_buffer() belongs in string.h

Cc Brian King <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/scsi/ipr.c |    1 +
 1 file changed, 1 insertion(+)

Index: 2.6-mm/drivers/scsi/ipr.c
===================================================================

drivers/scsi/ipr.c line 77

Quoted 7 lines
drivers/scsi/ipr.c +1 -0
@@ -71,6 +71,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/libata.h>
+#include <linux/string.h>
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/processor.h>

This isn't really necessary, is it? As you can see from the file being stuffed full of memcpy directives, it's already getting an implicit include of string.h from somewhere (like the rest of the SCSI drivers).

James

#8 lore raw

Re: [PATCH -mm] fix ipr-use-memory_read_from_buffer.patch

Quoted 6 lines
Quoted 6 lines
drivers/scsi/ipr.c +0 -0
@@ -71,6 +71,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/libata.h>
Quoted 8 lines

drivers/scsi/ipr.c line 77

Quoted 4 lines
drivers/scsi/ipr.c +1 -0
+#include <linux/string.h>
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/processor.h>

This isn't really necessary, is it? As you can see from the file being stuffed full of memcpy directives, it's already getting an implicit include of string.h from somewhere (like the rest of the SCSI drivers).

Indeed. This is not necessary.

#9 lore raw

PATCH 1/1 fix dcdbas-use-memory_read_from_buffer.patch

In reply to Akinobu Mita

Now memory_read_from_buffer() belongs in string.h

Cc Doug Warzecha <[email protected]>
Cc Zhang Rui <[email protected]>
Cc Matt Domsch <[email protected]>
---
 drivers/firmware/dcdbas.c |    1 -
 1 file changed, 1 deletion(-)
drivers/firmware/dcdbas.c +0 -1
Index: 2.6-mm/drivers/firmware/dcdbas.c
===================================================================
@@ -34,7 +34,6 @@
 #include <linux/string.h>
 #include <linux/types.h>
 #include <linux/mutex.h>
-#include <linux/fs.h>
 #include <asm/io.h>
 
 #include "dcdbas.h"
#10 lore raw

PATCH 1/1 fix aty-use-memory_read_from_buffer.patch

In reply to Akinobu Mita

Now memory_read_from_buffer() belongs in string.h

Cc Benjamin Herrenschmidt <[email protected]>
Cc "Antonino A. Daplas" <[email protected]>
Cc Krzysztof Helt <[email protected]>
---
 drivers/video/aty/radeon_base.c |    1 -
 1 file changed, 1 deletion(-)
drivers/video/aty/radeon_base.c +0 -1
Index: 2.6-mm/drivers/video/aty/radeon_base.c
===================================================================
@@ -70,7 +70,6 @@
 #include <linux/pci.h>
 #include <linux/vmalloc.h>
 #include <linux/device.h>
-#include <linux/fs.h>
 
 #include <asm/io.h>
 #include <linux/uaccess.h>
#11 lore raw

PATCH 1/1 fix firmware-use-memory_read_from_buffer.patch

In reply to Akinobu Mita

Now memory_read_from_buffer() belongs in string.h

Cc Greg Kroah-Hartman <[email protected]>
Cc Markus Rechberger <[email protected]>
Cc Kay Sievers <[email protected]>
---
 drivers/base/firmware_class.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/firmware_class.c +1 -1
Index: 2.6-mm/drivers/base/firmware_class.c
===================================================================
@@ -17,7 +17,7 @@
 #include <linux/bitops.h>
 #include <linux/mutex.h>
 #include <linux/kthread.h>
-#include <linux/fs.h>
+#include <linux/string.h>
 
 #include <linux/firmware.h>
 #include "base.h"
#12 lore raw

PATCH 1/1 fix dell_rbu-use-memory_read_from_buffer.patch

In reply to Akinobu Mita

Now memory_read_from_buffer() belongs in string.h

Cc Abhay Salunke <[email protected]>
Cc Zhang Rui <[email protected]>
Cc Matt Domsch <[email protected]>
---
 drivers/firmware/dell_rbu.c |    1 -
 1 file changed, 1 deletion(-)
drivers/firmware/dell_rbu.c +0 -1
Index: 2.6-mm/drivers/firmware/dell_rbu.c
===================================================================
@@ -44,7 +44,6 @@
 #include <linux/moduleparam.h>
 #include <linux/firmware.h>
 #include <linux/dma-mapping.h>
-#include <linux/fs.h>
 
 MODULE_AUTHOR("Abhay Salunke <[email protected]>");
 MODULE_DESCRIPTION("Driver for updating BIOS image on DELL systems");