mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: linux1394-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org, PaX Team <pageexec@freemail.hu>
Subject: [PATCH 5/6] firewire: reduce some memsets
Date: Sun, 6 Sep 2009 18:50:56 +0200 (CEST)	[thread overview]
Message-ID: <tkrat.1d38de48035e916f@s5r6.in-berlin.de> (raw)
In-Reply-To: <tkrat.85bb80d9295444c1@s5r6.in-berlin.de>

The 1 kBytes big config ROM was cleared to zero twice at each update.
It is only necessary to clear the trailing unused space in the ROM, and
only once.

While we are at it, replace the trivial fw_memcpy_to_be32() helper by
its open-coded equivalent.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
---
 drivers/firewire/core-card.c |    4 +---
 drivers/firewire/ohci.c      |   17 ++++++++++++-----
 include/linux/firewire.h     |    4 ----
 3 files changed, 13 insertions(+), 12 deletions(-)

Index: linux-2.6.31-rc9/drivers/firewire/core-card.c
===================================================================
--- linux-2.6.31-rc9.orig/drivers/firewire/core-card.c
+++ linux-2.6.31-rc9/drivers/firewire/core-card.c
@@ -80,46 +80,44 @@ static int descriptor_count;
 static u32 *generate_config_rom(struct fw_card *card, size_t *config_rom_length)
 {
 	struct fw_descriptor *desc;
 	static u32 config_rom[256];
 	int i, j, length;
 
 	/*
 	 * Initialize contents of config rom buffer.  On the OHCI
 	 * controller, block reads to the config rom accesses the host
 	 * memory, but quadlet read access the hardware bus info block
 	 * registers.  That's just crack, but it means we should make
 	 * sure the contents of bus info block in host memory matches
 	 * the version stored in the OHCI registers.
 	 */
 
-	memset(config_rom, 0, sizeof(config_rom));
 	config_rom[0] = BIB_CRC_LENGTH(4) | BIB_INFO_LENGTH(4) | BIB_CRC(0);
 	config_rom[1] = 0x31333934;
 
 	config_rom[2] =
 		BIB_LINK_SPEED(card->link_speed) |
 		BIB_GENERATION(card->config_rom_generation++ % 14 + 2) |
 		BIB_MAX_ROM(2) |
 		BIB_MAX_RECEIVE(card->max_receive) |
 		BIB_BMC | BIB_ISC | BIB_CMC | BIB_IMC;
 	config_rom[3] = card->guid >> 32;
 	config_rom[4] = card->guid;
 
 	/* Generate root directory. */
-	i = 5;
-	config_rom[i++] = 0;
+	i = 6;
 	config_rom[i++] = 0x0c0083c0; /* node capabilities */
 	j = i + descriptor_count;
 
 	/* Generate root directory entries for descriptors. */
 	list_for_each_entry (desc, &descriptor_list, link) {
 		if (desc->immediate > 0)
 			config_rom[i++] = desc->immediate;
 		config_rom[i] = desc->key | (j - i);
 		i++;
 		j += desc->length;
 	}
 
 	/* Update root directory length. */
 	config_rom[5] = (i - 5 - 1) << 16;
 
Index: linux-2.6.31-rc9/drivers/firewire/ohci.c
===================================================================
--- linux-2.6.31-rc9.orig/drivers/firewire/ohci.c
+++ linux-2.6.31-rc9/drivers/firewire/ohci.c
@@ -1464,6 +1464,16 @@ static int software_reset(struct fw_ohci
 	return -EBUSY;
 }
 
+static void copy_config_rom(__be32 *dest, const u32 *src, size_t length)
+{
+	int i;
+
+	for (i = 0; i < length; i++)
+		dest[i] = cpu_to_be32(src[i]);
+
+	memset(&dest[length], 0, CONFIG_ROM_SIZE - length * 4);
+}
+
 static int ohci_enable(struct fw_card *card, u32 *config_rom, size_t length)
 {
 	struct fw_ohci *ohci = fw_ohci(card);
@@ -1565,8 +1575,7 @@ static int ohci_enable(struct fw_card *c
 		if (ohci->next_config_rom == NULL)
 			return -ENOMEM;
 
-		memset(ohci->next_config_rom, 0, CONFIG_ROM_SIZE);
-		fw_memcpy_to_be32(ohci->next_config_rom, config_rom, length * 4);
+		copy_config_rom(ohci->next_config_rom, config_rom, length);
 	} else {
 		/*
 		 * In the suspend case, config_rom is NULL, which
@@ -1659,9 +1668,7 @@ static int ohci_set_config_rom(struct fw
 		ohci->next_config_rom = next_config_rom;
 		ohci->next_config_rom_bus = next_config_rom_bus;
 
-		memset(ohci->next_config_rom, 0, CONFIG_ROM_SIZE);
-		fw_memcpy_to_be32(ohci->next_config_rom, config_rom,
-				  length * 4);
+		copy_config_rom(ohci->next_config_rom, config_rom, length);
 
 		ohci->next_header = config_rom[0];
 		ohci->next_config_rom[0] = 0;
Index: linux-2.6.31-rc9/include/linux/firewire.h
===================================================================
--- linux-2.6.31-rc9.orig/include/linux/firewire.h
+++ linux-2.6.31-rc9/include/linux/firewire.h
@@ -30,10 +30,6 @@ static inline void fw_memcpy_from_be32(v
 		dst[i] = be32_to_cpu(src[i]);
 }
 
-static inline void fw_memcpy_to_be32(void *_dst, void *_src, size_t size)
-{
-	fw_memcpy_from_be32(_dst, _src, size);
-}
 #define CSR_REGISTER_BASE		0xfffff0000000ULL
 
 /* register offsets are relative to CSR_REGISTER_BASE */

-- 
Stefan Richter
-=====-==--= =--= --==-
http://arcgraph.de/sr/


  parent reply	other threads:[~2009-09-06 16:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-06 16:46 [PATCH 0/6] firewire: minor fixes and cleanups Stefan Richter
2009-09-06 16:48 ` [PATCH 1/6] firewire: core: reduce stack usage in bus reset tasklet Stefan Richter
2009-09-07 19:02   ` pageexec
2009-09-07 19:15     ` Stefan Richter
2009-09-07 21:24       ` Stefan Richter
2009-09-06 16:49 ` [PATCH 2/6] firewire: ohci: fix Self ID Count register mask (safeguard against buffer overflow) Stefan Richter
2009-09-07 18:56   ` pageexec
2009-09-07 19:28     ` Stefan Richter
2009-09-06 16:49 ` [PATCH 3/6] firewire: core: header file cleanup Stefan Richter
2009-09-06 16:50 ` [PATCH 4/6] firewire: core: fix race with parallel PCI device probe Stefan Richter
2009-09-06 16:50 ` Stefan Richter [this message]
2009-09-06 16:51 ` [PATCH 6/6] firewire: sbp2: fix status reception Stefan Richter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tkrat.1d38de48035e916f@s5r6.in-berlin.de \
    --to=stefanr@s5r6.in-berlin.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux1394-devel@lists.sourceforge.net \
    --cc=pageexec@freemail.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®