From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: linux-kernel@vger.kernel.org
Cc: linux1394-devel@lists.sourceforge.net,
Clemens Ladisch <cladisch@fastmail.net>
Subject: [PATCH 2/3] firewire: core: fw_csr_string addendum
Date: Sat, 26 Dec 2009 01:43:21 +0100 (CET) [thread overview]
Message-ID: <tkrat.2c5d2d0397876ecd@s5r6.in-berlin.de> (raw)
In-Reply-To: <tkrat.d7a89db5096e31cd@s5r6.in-berlin.de>
Witespace and comment changes, and a different way to say i + 1 < end.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
---
drivers/firewire/core-device.c | 26 ++++++++++++++++----------
include/linux/firewire.h | 1 -
2 files changed, 16 insertions(+), 11 deletions(-)
Index: linux-2.6.33-rc2/drivers/firewire/core-device.c
===================================================================
--- linux-2.6.33-rc2.orig/drivers/firewire/core-device.c
+++ linux-2.6.33-rc2/drivers/firewire/core-device.c
@@ -69,19 +69,22 @@ static u32 *search_leaf(u32 *directory,
if (last_key == search_key &&
key == (CSR_DESCRIPTOR | CSR_LEAF))
return ci.p - 1 + value;
+
last_key = key;
}
+
return NULL;
}
static int textual_leaf_to_string(u32 *block, char *buf, size_t size)
{
- unsigned int quadlets, length;
+ unsigned int quadlets, i;
+ char c;
if (!size || !buf)
return -EINVAL;
- quadlets = min(block[0] >> 16, 256u);
+ quadlets = min(block[0] >> 16, 256U);
if (quadlets < 2)
return -ENODATA;
@@ -91,31 +94,34 @@ static int textual_leaf_to_string(u32 *b
block += 3;
quadlets -= 2;
- for (length = 0; length < quadlets * 4 && length + 1 < size; length++) {
- char c = block[length / 4] >> (24 - 8 * (length % 4));
+ for (i = 0; i < quadlets * 4 && i < size - 1; i++) {
+ c = block[i / 4] >> (24 - 8 * (i % 4));
if (c == '\0')
break;
- buf[length] = c;
+ buf[i] = c;
}
- buf[length] = '\0';
- return length;
+ buf[i] = '\0';
+
+ return i;
}
/**
* fw_csr_string - reads a string from the configuration ROM
- * @directory: device or unit directory;
- * fw_device->config_rom+5 or fw_unit->directory
+ * @directory: e.g. root directory or unit directory
* @key: the key of the preceding directory entry
* @buf: where to put the string
* @size: size of @buf, in bytes
*
- * Returns string length (>= 0) or error code (< 0).
+ * The string is taken from a minimal ASCII text descriptor leaf after
+ * the immediate entry with @key. The string is zero-terminated.
+ * Returns strlen(buf) or a negative error code.
*/
int fw_csr_string(u32 *directory, int key, char *buf, size_t size)
{
u32 *leaf = search_leaf(directory, key);
if (!leaf)
return -ENOENT;
+
return textual_leaf_to_string(leaf, buf, size);
}
EXPORT_SYMBOL(fw_csr_string);
Index: linux-2.6.33-rc2/include/linux/firewire.h
===================================================================
--- linux-2.6.33-rc2.orig/include/linux/firewire.h
+++ linux-2.6.33-rc2/include/linux/firewire.h
@@ -71,7 +71,6 @@ struct fw_csr_iterator {
void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p);
int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value);
-
int fw_csr_string(u32 *directory, int key, char *buf, size_t size);
extern struct bus_type fw_bus_type;
--
Stefan Richter
-=====-==--= ==-- ==-=-
http://arcgraph.de/sr/
next prev parent reply other threads:[~2009-12-26 0:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-26 0:41 [PATCH 0/3] firewire: small refactoring Stefan Richter
2009-12-26 0:42 ` [PATCH 1/3 resend] firewire: add fw_csr_string() helper function Stefan Richter
2009-12-26 0:43 ` Stefan Richter [this message]
2009-12-26 0:44 ` [PATCH 3/3] firewire: qualify config ROM cache pointers as const pointers 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.2c5d2d0397876ecd@s5r6.in-berlin.de \
--to=stefanr@s5r6.in-berlin.de \
--cc=cladisch@fastmail.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux1394-devel@lists.sourceforge.net \
/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
Powered by JetHome