Skip to contentSkip to conversation

: MEMSTICK: My 2 drivers for 2.6.38 inclusion

PATCH In review Maxim Levitsky 3 participants 11 messages Jan 11, 2011 – Jan 18, 2011

Subsystems (3)
lore
Share & tools
lore

Maxim Levitsky

author maintainer
#0 lore raw

v2 cover : MEMSTICK: My 2 drivers for 2.6.38 inclusion

Hi, this is pretty much same version as I sent yestarday. I did a proofread of the commit messages, did a review of ms_block.c during which I found misspelled debug message, and verified that my port to sg_mitter in code that fills the sg with 0xFF really works.

This is pretty much merge worthy.

patch 1 - only commit message change
patch 2 - unchanged
patch 3 - commit message change + trivial string change patch 4 - fix for a typo in contents

author maintainer
#1 lore raw

PATCH v2 1/4 scatterlist: new helper functions

While developing memstick driver for legacy memsticks I found the need in few helpers that I think should be in common scatterlist library

The functions that were added:

* sg_nents/sg_total_len - iterate over scatterlist to figure out total length of memory it covers / number of entries. Useful for not keeping that information in side channels.

* sg_copy/sg_advance - Allow to break scatterlists apart into smaller chunks. sg_copy creates smaller scatterlist, spanning first 'len' bytes, while sg_advance edits the scatterlist in such way that it skips over 'len' bytes.

* sg_compare_to_buffer - another function to hide gory details of access to sg list by CPU.
Allows to transparently compare contents of the sg list to given linear buffer.
If needed later, a function that compares two sgs can be added.

All of this code is used by my ms_block.c driver.

---
 include/linux/scatterlist.h |    6 ++
 lib/scatterlist.c           |  137 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 143 insertions(+), 0 deletions(-)
include/linux/scatterlist.h +6 -0
index 9aaf5bf..6305589 100644
@@ -199,6 +199,11 @@ static inline void *sg_virt(struct scatterlist *sg)
 	return page_address(sg_page(sg)) + sg->offset;
 }
 
+struct scatterlist *sg_advance(struct scatterlist *sg, int consumed);
+int sg_nents(struct scatterlist *sg);
+int sg_total_len(struct scatterlist *sg);
+int sg_copy(struct scatterlist *sg_from, struct scatterlist *sg_to, int len);
+
 struct scatterlist *sg_next(struct scatterlist *);
 struct scatterlist *sg_last(struct scatterlist *s, unsigned int);
 void sg_init_table(struct scatterlist *, unsigned int);
@@ -217,6 +222,7 @@ size_t sg_copy_from_buffer(struct scatterlist *sgl, unsigned int nents,
 			   void *buf, size_t buflen);
 size_t sg_copy_to_buffer(struct scatterlist *sgl, unsigned int nents,
 			 void *buf, size_t buflen);
+bool sg_compare_to_buffer(struct scatterlist *sg, u8 *buffer, size_t len);
 
 /*
  * Maximum number of entries that will be allocated in one piece, if
lib/scatterlist.c +137 -0

152 lines not on this page · raw message

Signature · 1 line
1.7.1
#2 lore raw

Re: [PATCH 1/4] scatterlist: new helper functions

Quoted 34 lines · On Wed, 12 Jan 2011 01:36:12 +0200 Maxim Levitsky wrote:

While developing memstick driver for legacy memsticks I found the need in few helpers that I think should be in common scatterlist library

The functions that were added:

* sg_nents/sg_total_len - iterate over scatterlist to figure out total length of memory it covers / number of entries. Useful for not keeping that information in side channels.

* sg_copy/sg_advance - Allow to break scatterlists apart into smaller chunks. sg_copy creates smaller scatterlist, spanning first 'len' bytes, while sg_advance edits the scatterlist in such way that it skips over 'len' bytes.

* sg_compare_to_buffer - another function to hide gory details of access to sg list by CPU.
Allows to transparently compare contents of the sg list to given linear buffer.
If needed later, a function that compares two sgs can be added.

All of this code is used by my ms_block.c driver.

---
 include/linux/scatterlist.h |    6 ++
 lib/scatterlist.c           |  137 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 143 insertions(+), 0 deletions(-)
lib/scatterlist.c +0 -0
index 4ceb05d..2f18938 100644

lib/scatterlist.c struct scatterlist *sg_next(struct scatterlist *sg) · line 44

Quoted 6 lines
lib/scatterlist.c +3 -0
@@ -39,6 +39,77 @@ struct scatterlist *sg_next(struct scatterlist *sg)
 EXPORT_SYMBOL(sg_next);
 
 /**
+ * sg_advance - advance scatterlist by 'consumed' bytes
+ * @sg - the current sg entry
+ * @consumed - how much bytes to advance

kernel-doc notation for parameters is like so:

* @sg: the current sg entry

lib/scatterlist.c struct scatterlist *sg_next(struct scatterlist *sg) · line 45

Quoted 1 line
lib/scatterlist.c +1 -0
+ *

no empty line, please.

Quoted 22 lines
lib/scatterlist.c +22 -0
+ */
+struct scatterlist *sg_advance(struct scatterlist *sg, int consumed)
+{
+	while (consumed >= sg->length) {
+		consumed -= sg->length;
+
+		sg = sg_next(sg);
+		if (!sg)
+			break;
+	}
+
+	WARN_ON(!sg && consumed);
+
+	if (!sg)
+		return NULL;
+
+	sg->offset += consumed;
+	sg->length -= consumed;
+
+	if (sg->offset >= PAGE_SIZE) {
+		struct page *page =
+			nth_page(sg_page(sg), sg->offset / PAGE_SIZE);

lib/scatterlist.c struct scatterlist *sg_next(struct scatterlist *sg) · line 77

Quoted 10 lines
lib/scatterlist.c +10 -0
+		sg_set_page(sg, page, sg->length, sg->offset % PAGE_SIZE);
+	}
+
+	return sg;
+}
+EXPORT_SYMBOL(sg_advance);
+
+/**
+ * sg_nents - calculate number of sg entries in sg list
+ * @sg - the current sg entry

* @sg:

lib/scatterlist.c struct scatterlist *sg_next(struct scatterlist *sg) · line 79

Quoted 2 lines
lib/scatterlist.c +2 -0
+ *
+ * Allows to calculate dynamicly the lenght of the sg table, based on

dynamically the length

Quoted 6 lines
lib/scatterlist.c +6 -0
+ * assumption that last entry is NULL
+ */
+int sg_nents(struct scatterlist *sg)
+{
+	int nents = 0;
+	while (sg) {

lib/scatterlist.c struct scatterlist *sg_next(struct scatterlist *sg) · line 95

Quoted 10 lines
lib/scatterlist.c +10 -0
+		nents++;
+		sg = sg_next(sg);
+	}
+
+	return nents;
+}
+EXPORT_SYMBOL(sg_nents);
+
+/**
+ * sg_total_len - calculate total lenght of scatterlist

length

lib/scatterlist.c struct scatterlist *sg_next(struct scatterlist *sg) · line 96

Quoted 1 line
lib/scatterlist.c +1 -0
+ * @sg - the current sg entry

* @sg:

lib/scatterlist.c struct scatterlist *sg_next(struct scatterlist *sg) · line 98

Quoted 2 lines
lib/scatterlist.c +2 -0
+ *
+ * Dynamicly calculate total number of bytes in a sg list

Dynamically in an sg list

Quoted 18 lines
lib/scatterlist.c +14 -0
+ * based on assumption that list ends with a NULL entry
+ */
+int sg_total_len(struct scatterlist *sg)
+{
+	int len = 0;
+	while (sg) {
+		len += sg->length;
+		sg = sg_next(sg);
+	}
+	return len;
+}
+EXPORT_SYMBOL(sg_total_len);
+
+/**
  * sg_last - return the last scatterlist entry in a list
  * @sgl:	First entry in the scatterlist
  * @nents:	Number of entries in the scatterlist

lib/scatterlist.c void sg_init_one(struct scatterlist *sg, const void *buf, unsigned int buflen) · line 186

Quoted 6 lines
lib/scatterlist.c +3 -0
@@ -110,6 +181,33 @@ void sg_init_one(struct scatterlist *sg, const void *buf, unsigned int buflen)
 }
 EXPORT_SYMBOL(sg_init_one);
 
+/**
+ * sg_copy - copies sg entries from sg_from to sg_to, such
+ * as sg_to covers first 'len' bytes from sg_from.

Add function parameters to kernel-doc, please.

Quoted 28 lines
lib/scatterlist.c +24 -0
+ */
+int sg_copy(struct scatterlist *sg_from, struct scatterlist *sg_to, int len)
+{
+	while (len > sg_from->length) {
+		len -= sg_from->length;
+
+		sg_set_page(sg_to, sg_page(sg_from),
+				sg_from->length, sg_from->offset);
+
+		sg_to = sg_next(sg_to);
+		sg_from = sg_next(sg_from);
+
+		if (len && (!sg_from || !sg_to))
+			return -ENOMEM;
+	}
+
+	if (len)
+		sg_set_page(sg_to, sg_page(sg_from),
+				len, sg_from->offset);
+	sg_mark_end(sg_to);
+	return 0;
+}
+EXPORT_SYMBOL(sg_copy);
+
 /*
  * The default behaviour of sg_alloc_table() is to use these kmalloc/kfree
  * helpers.

lib/scatterlist.c size_t sg_copy_to_buffer(struct scatterlist *sgl, unsigned int nents, · line 621

Quoted 7 lines
lib/scatterlist.c +4 -0
@@ -517,3 +615,42 @@ size_t sg_copy_to_buffer(struct scatterlist *sgl, unsigned int nents,
 	return sg_copy_buffer(sgl, nents, buf, buflen, 1);
 }
 EXPORT_SYMBOL(sg_copy_to_buffer);
+
+
+/**
+ * sg_compare_to_buffer - compare contents of the data pointeted by sg table

pointed to by sg table

lib/scatterlist.c size_t sg_copy_to_buffer(struct scatterlist *sgl, unsigned int nents, · line 622

Quoted 1 line
lib/scatterlist.c +1 -0
+ * to a kernel ram buffer

RAM

lib/scatterlist.c size_t sg_copy_to_buffer(struct scatterlist *sgl, unsigned int nents, · line 625

Quoted 3 lines
lib/scatterlist.c +3 -0
+ * @sg - the current sg entry
+ * @buffer - linear buffer to compare with
+ * @len - lenght of that buffer

* @sg:
* @buffer:
* @len: length

Returns 0 for equal or what??

lib/scatterlist.c size_t sg_copy_to_buffer(struct scatterlist *sgl, unsigned int nents, · line 628

Quoted 3 lines
lib/scatterlist.c +3 -0
+ */
+bool sg_compare_to_buffer(struct scatterlist *sg, u8 *buffer, size_t len)
+{

Thanks for adding the kernel-doc.

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

maintainer
#3 lore raw

Re: [PATCH 1/4] scatterlist: new helper functions

Quoted 6 lines · On Tue, 11 Jan 2011 15:51:24 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 4 lines

/**
+ * sg_advance - advance scatterlist by 'consumed' bytes
+ * @sg - the current sg entry
+ * @consumed - how much bytes to advance

kernel-doc notation for parameters is like so:

I think I fixed most of this. Probably missed some though.

Teach checkpatch to check kerneldoc ;)

From: Andrew Morton <[email protected]>

fix general disaster in code comments

Cc Alex Dubov <[email protected]>
Cc James Bottomley <[email protected]>
Cc Jens Axboe <[email protected]>
Cc Maxim Levitsky <[email protected]>
Cc Tejun Heo <[email protected]>

---

 lib/scatterlist.c |   31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +18 -13
diff -puN lib/scatterlist.c~scatterlist-new-helper-functions-fix lib/scatterlist.c
@@ -41,7 +41,7 @@ EXPORT_SYMBOL(sg_next);
 /**
  * sg_advance - advance scatterlist by 'consumed' bytes
  * @sg - the current sg entry
- * @consumed - how much bytes to advance
+ * @consumed - how many bytes to advance
  *
  */
 struct scatterlist *sg_advance(struct scatterlist *sg, int consumed)
@@ -76,8 +76,8 @@ EXPORT_SYMBOL(sg_advance);
  * sg_nents - calculate number of sg entries in sg list
  * @sg - the current sg entry
  *
- * Allows to calculate dynamicly the lenght of the sg table, based on
- * assumption that last entry is NULL
+ * Allows to calculate aldynamicly the length of the sg table, based on an
+ * assumption that the last entry is NULL
  */
 int sg_nents(struct scatterlist *sg)
 {
@@ -92,11 +92,11 @@ int sg_nents(struct scatterlist *sg)
 EXPORT_SYMBOL(sg_nents);
 
 /**
- * sg_total_len - calculate total lenght of scatterlist
+ * sg_total_len - calculate total length of scatterlist
  * @sg - the current sg entry
  *
- * Dynamicly calculate total number of bytes in a sg list
- * based on assumption that list ends with a NULL entry
+ * Dynamically calculate total number of bytes in a sg list
+ * based on an assumption that the list ends with a NULL entry
  */
 int sg_total_len(struct scatterlist *sg)
 {
@@ -182,8 +182,14 @@ void sg_init_one(struct scatterlist *sg,
 EXPORT_SYMBOL(sg_init_one);
 
 /**
- * sg_copy - copies sg entries from sg_from to sg_to, such
- * as sg_to covers first 'len' bytes from sg_from.
+ * sg_copy - copy sg entries
+ * @sg_from: source
+ * @sg_to: destination
+ *
+ * Copies from @sg_from to @sg_to.  @sg_to covers first 'len' bytes from
+ * @sg_from.
+ *
+ * Returns zero on success, else a -ve errno.
  */
 int sg_copy(struct scatterlist *sg_from, struct scatterlist *sg_to, int len)
 {
@@ -616,13 +622,12 @@ size_t sg_copy_to_buffer(struct scatterl
 }
 EXPORT_SYMBOL(sg_copy_to_buffer);
 
-
 /**
- * sg_compare_to_buffer - compare contents of the data pointeted by sg table
+ * sg_compare_to_buffer - compare contents of the data covered by an sg table
  * to a kernel ram buffer
- * @sg - the current sg entry
- * @buffer - linear buffer to compare with
- * @len - lenght of that buffer
+ * @sg: the current sg entry
+ * @buffer: linear buffer to compare with
+ * @len: length of that buffer
  */
 bool sg_compare_to_buffer(struct scatterlist *sg, u8 *buffer, size_t len)
 {

_

#4 lore raw

Re: [PATCH 1/4] scatterlist: new helper functions

Quoted 8 lines · On Tue, 11 Jan 2011 15:55:11 -0800 Andrew Morton wrote:
Quoted 5 lines · On Tue, 11 Jan 2011 15:51:24 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 4 lines

/**
+ * sg_advance - advance scatterlist by 'consumed' bytes
+ * @sg - the current sg entry
+ * @consumed - how much bytes to advance

Quoted 6 lines
Quoted 1 line

kernel-doc notation for parameters is like so:

I think I fixed most of this. Probably missed some though.

Teach checkpatch to check kerneldoc ;)

ugh, no thanks.

Quoted 21 lines

From: Andrew Morton <[email protected]>

fix general disaster in code comments

Cc Alex Dubov <[email protected]>
Cc James Bottomley <[email protected]>
Cc Jens Axboe <[email protected]>
Cc Maxim Levitsky <[email protected]>
Cc Tejun Heo <[email protected]>

---

 lib/scatterlist.c |   31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff -puN lib/scatterlist.c~scatterlist-new-helper-functions-fix lib/scatterlist.c

lib/scatterlist.c EXPORT_SYMBOL(sg_next); · line 44

Quoted 5 lines
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +1 -1
@@ -41,7 +41,7 @@ EXPORT_SYMBOL(sg_next);
 /**
  * sg_advance - advance scatterlist by 'consumed' bytes
  * @sg - the current sg entry
- * @consumed - how much bytes to advance
+ * @consumed - how many bytes to advance

* @consumed: how many bytes to advance

lib/scatterlist.c EXPORT_SYMBOL(sg_advance); · line 77

Quoted 6 lines
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +0 -0
  *
  */
 struct scatterlist *sg_advance(struct scatterlist *sg, int consumed)
@@ -76,8 +76,8 @@ EXPORT_SYMBOL(sg_advance);
  * sg_nents - calculate number of sg entries in sg list
  * @sg - the current sg entry

* @sg:

Quoted 9 lines
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +2 -2
  *
- * Allows to calculate dynamicly the lenght of the sg table, based on
- * assumption that last entry is NULL
+ * Allows to calculate aldynamicly the length of the sg table, based on an
+ * assumption that the last entry is NULL
  */
 int sg_nents(struct scatterlist *sg)
 {

lib/scatterlist.c int sg_nents(struct scatterlist *sg) · line 96

Quoted 6 lines
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +1 -1
@@ -92,11 +92,11 @@ int sg_nents(struct scatterlist *sg)
 EXPORT_SYMBOL(sg_nents);
 
 /**
- * sg_total_len - calculate total lenght of scatterlist
+ * sg_total_len - calculate total length of scatterlist
  * @sg - the current sg entry

* @sg:

lib/scatterlist.c int sg_nents(struct scatterlist *sg) · line 98

Quoted 4 lines
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +1 -2
  *
- * Dynamicly calculate total number of bytes in a sg list
- * based on assumption that list ends with a NULL entry
+ * Dynamically calculate total number of bytes in a sg list

preferably:
in an sg list

Quoted 26 lines
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +9 -3
+ * based on an assumption that the list ends with a NULL entry
  */
 int sg_total_len(struct scatterlist *sg)
 {
@@ -182,8 +182,14 @@ void sg_init_one(struct scatterlist *sg,
 EXPORT_SYMBOL(sg_init_one);
 
 /**
- * sg_copy - copies sg entries from sg_from to sg_to, such
- * as sg_to covers first 'len' bytes from sg_from.
+ * sg_copy - copy sg entries
+ * @sg_from: source
+ * @sg_to: destination
+ *
+ * Copies from @sg_from to @sg_to.  @sg_to covers first 'len' bytes from
+ * @sg_from.
+ *
+ * Returns zero on success, else a -ve errno.
  */
 int sg_copy(struct scatterlist *sg_from, struct scatterlist *sg_to, int len)
 {
@@ -616,13 +622,12 @@ size_t sg_copy_to_buffer(struct scatterl
 }
 EXPORT_SYMBOL(sg_copy_to_buffer);
 
-

lib/scatterlist.c size_t sg_copy_to_buffer(struct scatterl · line 630

Quoted 10 lines
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +4 -4
 /**
- * sg_compare_to_buffer - compare contents of the data pointeted by sg table
+ * sg_compare_to_buffer - compare contents of the data covered by an sg table
  * to a kernel ram buffer
- * @sg - the current sg entry
- * @buffer - linear buffer to compare with
- * @len - lenght of that buffer
+ * @sg: the current sg entry
+ * @buffer: linear buffer to compare with
+ * @len: length of that buffer

Returns what??

Quoted 5 lines
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +0 -0
  */
 bool sg_compare_to_buffer(struct scatterlist *sg, u8 *buffer, size_t len)
 {

_

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

author maintainer
#5 lore raw

Re: [PATCH 1/4] scatterlist: new helper functions

Quoted 108 lines · Randy Dunlap
Quoted 8 lines · On Tue, 11 Jan 2011 15:55:11 -0800 Andrew Morton wrote:
Quoted 5 lines · On Tue, 11 Jan 2011 15:51:24 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 4 lines

/**
+ * sg_advance - advance scatterlist by 'consumed' bytes
+ * @sg - the current sg entry
+ * @consumed - how much bytes to advance

Quoted 6 lines
Quoted 1 line

kernel-doc notation for parameters is like so:

I think I fixed most of this. Probably missed some though.

Teach checkpatch to check kerneldoc ;)

ugh, no thanks.

Quoted 21 lines

From: Andrew Morton <[email protected]>

fix general disaster in code comments

Cc Alex Dubov <[email protected]>
Cc James Bottomley <[email protected]>
Cc Jens Axboe <[email protected]>
Cc Maxim Levitsky <[email protected]>
Cc Tejun Heo <[email protected]>

---

 lib/scatterlist.c |   31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff -puN lib/scatterlist.c~scatterlist-new-helper-functions-fix lib/scatterlist.c

lib/scatterlist.c EXPORT_SYMBOL(sg_next); · line 44

Quoted 5 lines
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +1 -1
@@ -41,7 +41,7 @@ EXPORT_SYMBOL(sg_next);
 /**
  * sg_advance - advance scatterlist by 'consumed' bytes
  * @sg - the current sg entry
- * @consumed - how much bytes to advance
+ * @consumed - how many bytes to advance

* @consumed: how many bytes to advance

lib/scatterlist.c EXPORT_SYMBOL(sg_advance); · line 77

Quoted 6 lines
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +0 -0
  *
  */
 struct scatterlist *sg_advance(struct scatterlist *sg, int consumed)
@@ -76,8 +76,8 @@ EXPORT_SYMBOL(sg_advance);
  * sg_nents - calculate number of sg entries in sg list
  * @sg - the current sg entry

* @sg:

Quoted 9 lines
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +2 -2
  *
- * Allows to calculate dynamicly the lenght of the sg table, based on
- * assumption that last entry is NULL
+ * Allows to calculate aldynamicly the length of the sg table, based on an
+ * assumption that the last entry is NULL
  */
 int sg_nents(struct scatterlist *sg)
 {

lib/scatterlist.c int sg_nents(struct scatterlist *sg) · line 96

Quoted 6 lines
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +1 -1
@@ -92,11 +92,11 @@ int sg_nents(struct scatterlist *sg)
 EXPORT_SYMBOL(sg_nents);
 
 /**
- * sg_total_len - calculate total lenght of scatterlist
+ * sg_total_len - calculate total length of scatterlist
  * @sg - the current sg entry

* @sg:

lib/scatterlist.c int sg_nents(struct scatterlist *sg) · line 98

Quoted 4 lines
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +1 -2
  *
- * Dynamicly calculate total number of bytes in a sg list
- * based on assumption that list ends with a NULL entry
+ * Dynamically calculate total number of bytes in a sg list

preferably:
in an sg list

Quoted 25 lines
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +9 -2
+ * based on an assumption that the list ends with a NULL entry
  */
 int sg_total_len(struct scatterlist *sg)
 {
@@ -182,8 +182,14 @@ void sg_init_one(struct scatterlist *sg,
 EXPORT_SYMBOL(sg_init_one);
 
 /**
- * sg_copy - copies sg entries from sg_from to sg_to, such
- * as sg_to covers first 'len' bytes from sg_from.
+ * sg_copy - copy sg entries
+ * @sg_from: source
+ * @sg_to: destination
+ *
+ * Copies from @sg_from to @sg_to.  @sg_to covers first 'len' bytes from
+ * @sg_from.
+ *
+ * Returns zero on success, else a -ve errno.
  */
 int sg_copy(struct scatterlist *sg_from, struct scatterlist *sg_to, int len)
 {
@@ -616,13 +622,12 @@ size_t sg_copy_to_buffer(struct scatterl
 }
 EXPORT_SYMBOL(sg_copy_to_buffer);
 
Quoted 13 lines

lib/scatterlist.c size_t sg_copy_to_buffer(struct scatterl · line 630

Quoted 11 lines
lib/scatterlist.c renamed from lib/scatterlist.c~scatterlist-new-helper-functions-fix +4 -5
-
 /**
- * sg_compare_to_buffer - compare contents of the data pointeted by sg table
+ * sg_compare_to_buffer - compare contents of the data covered by an sg table
  * to a kernel ram buffer
- * @sg - the current sg entry
- * @buffer - linear buffer to compare with
- * @len - lenght of that buffer
+ * @sg: the current sg entry
+ * @buffer: linear buffer to compare with
+ * @len: length of that buffer

Returns what??

0 if equal and 1 otherwise.
Was too lazy to implement full strcmp compliance. Is that needed?

All very fair comments.
Will check everything once again. Thanks for a review!

Best regards,
Maxim Levitsky

#6 lore raw

Re: [PATCH 1/4] scatterlist: new helper functions

Quoted 11 lines · On Wed, 12 Jan 2011 04:52:29 +0200 Maxim Levitsky wrote:
Quoted 11 lines
Quoted 10 lines

/**
- * sg_compare_to_buffer - compare contents of the data pointeted by sg table
+ * sg_compare_to_buffer - compare contents of the data covered by an sg table
* to a kernel ram buffer
- * @sg - the current sg entry
- * @buffer - linear buffer to compare with
- * @len - lenght of that buffer
+ * @sg: the current sg entry
+ * @buffer: linear buffer to compare with
+ * @len: length of that buffer

Quoted 4 lines
Quoted 1 line

Returns what??

0 if equal and 1 otherwise.
Was too lazy to implement full strcmp compliance. Is that needed?

Not that I know of, just what the function returns was needed.

Quoted 8 lines

All very fair comments.
Will check everything once again. Thanks for a review!

Best regards,
Maxim Levitsky

--

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

author maintainer
#7 lore raw

PATCH 1/1 scatterlist: new helper functions

In reply to Maxim Levitsky

I hopefully addressed all comments on this code.
Can now my code be merged?

Best regards,
Maxim Levitsky

While developing memstick driver for legacy memsticks I found the need in few helpers that I think should be in common scatterlist library

The functions that were added:

* sg_nents/sg_total_len - iterate over scatterlist to figure out total length of memory it covers / number of entries. Useful for not keeping that information in side channels.

* sg_copy/sg_advance - Allow to break scatterlists apart into smaller chunks. sg_copy creates smaller scatterlist, spanning first 'len' bytes, while sg_advance edits the scatterlist in such way that it skips over 'len' bytes.

* sg_compare_to_buffer - another function to hide gory details of access to sg list by CPU.
Allows to transparently compare contents of the sg list to given linear buffer.
If needed later, a function that compares two sgs can be added.

All of this code is used by my ms_block.c driver.

---
 include/linux/scatterlist.h |    6 ++
 lib/scatterlist.c           |  138 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 144 insertions(+), 0 deletions(-)
include/linux/scatterlist.h +6 -0
index 9aaf5bf..6305589 100644
@@ -199,6 +199,11 @@ static inline void *sg_virt(struct scatterlist *sg)
 	return page_address(sg_page(sg)) + sg->offset;
 }
 
+struct scatterlist *sg_advance(struct scatterlist *sg, int consumed);
+int sg_nents(struct scatterlist *sg);
+int sg_total_len(struct scatterlist *sg);
+int sg_copy(struct scatterlist *sg_from, struct scatterlist *sg_to, int len);
+
 struct scatterlist *sg_next(struct scatterlist *);
 struct scatterlist *sg_last(struct scatterlist *s, unsigned int);
 void sg_init_table(struct scatterlist *, unsigned int);
@@ -217,6 +222,7 @@ size_t sg_copy_from_buffer(struct scatterlist *sgl, unsigned int nents,
 			   void *buf, size_t buflen);
 size_t sg_copy_to_buffer(struct scatterlist *sgl, unsigned int nents,
 			 void *buf, size_t buflen);
+bool sg_compare_to_buffer(struct scatterlist *sg, u8 *buffer, size_t len);
 
 /*
  * Maximum number of entries that will be allocated in one piece, if
lib/scatterlist.c +138 -0

153 lines not on this page · raw message

Signature · 1 line
1.7.1
author maintainer
#8 lore raw

PATCH v2 2/4 memstick: Add driver for Ricoh R5C592 card reader.

In reply to Maxim Levitsky
---
 MAINTAINERS                    |    5 +
 drivers/memstick/host/Kconfig  |   12 +
 drivers/memstick/host/Makefile |    1 +
 drivers/memstick/host/r592.c   |  908 ++++++++++++++++++++++++++++++++++++++++
 drivers/memstick/host/r592.h   |  175 ++++++++
 5 files changed, 1101 insertions(+), 0 deletions(-)
 create mode 100644 drivers/memstick/host/r592.c
 create mode 100644 drivers/memstick/host/r592.h
MAINTAINERS +5 -0
index bcb7830..d3aec27 100644
@@ -5059,6 +5059,11 @@ S:	Maintained
 F:	drivers/mtd/nand/r852.c
 F:	drivers/mtd/nand/r852.h
 
+RICOH R5C592 MEMORYSTICK DRIVER
+M:	Maxim Levitsky <[email protected]>
+S:	Maintained
+F:	drivers/memstick/host/r592.*
+
 RISCOM8 DRIVER
 S:	Orphan
 F:	Documentation/serial/riscom8.txt
drivers/memstick/host/Kconfig +12 -0
index 4ce5c8d..cc0997a 100644
@@ -30,3 +30,15 @@ config MEMSTICK_JMICRON_38X
 
           To compile this driver as a module, choose M here: the
 	  module will be called jmb38x_ms.
+
+config MEMSTICK_R592
+	tristate "Ricoh R5C592 MemoryStick interface support (EXPERIMENTAL)"
+	depends on EXPERIMENTAL && PCI
+
+	help
+	  Say Y here if you want to be able to access MemoryStick cards with
+	  the Ricoh R5C592 MemoryStick card reader (which is part of 5 in one
+		multifunction reader)
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called r592.
drivers/memstick/host/Makefile +1 -0
index 12530e4..ad63c16 100644
@@ -8,3 +8,4 @@ endif
 
 obj-$(CONFIG_MEMSTICK_TIFM_MS)		+= tifm_ms.o
 obj-$(CONFIG_MEMSTICK_JMICRON_38X)	+= jmb38x_ms.o
+obj-$(CONFIG_MEMSTICK_R592)		+= r592.o
drivers/memstick/host/r592.c new file +908 -0

908 lines not on this page · raw message

drivers/memstick/host/r592.h new file +175 -0

175 lines not on this page · raw message

Signature · 1 line
1.7.1
author maintainer
#9 lore raw

PATCH v2 3/4 memstick: add support for legacy memorysticks

In reply to Maxim Levitsky

Based partially on MS standard spec quotes from Alex Dubov.

As any code that works with user data this driver isn't recommended to use to write cards that contain valuable data.

It tries its best though to avoid data corruption
and possible damage to the card.

Tested on MS DUO 64 MB card on Ricoh R592 card reader.

---
 MAINTAINERS                      |    5 +
 drivers/memstick/core/Kconfig    |   12 +
 drivers/memstick/core/Makefile   |    2 +-
 drivers/memstick/core/ms_block.c | 2285 ++++++++++++++++++++++++++++++++++++++
 drivers/memstick/core/ms_block.h |  245 ++++
 5 files changed, 2548 insertions(+), 1 deletions(-)
 create mode 100644 drivers/memstick/core/ms_block.c
 create mode 100644 drivers/memstick/core/ms_block.h
MAINTAINERS +5 -0
index d3aec27..c9293f7 100644
@@ -5620,6 +5620,11 @@ W:	http://tifmxx.berlios.de/
 S:	Maintained
 F:	drivers/memstick/host/tifm_ms.c
 
+SONY MEMORYSTICK STANDARD SUPPORT
+M:	Maxim Levitsky <[email protected]>
+S:	Maintained
+F:	drivers/memstick/core/ms_block.*
+
 SOUND
 M:	Jaroslav Kysela <[email protected]>
 M:	Takashi Iwai <[email protected]>
drivers/memstick/core/Kconfig +12 -0
index 95f1814..f79f2a8 100644
@@ -24,3 +24,15 @@ config MSPRO_BLOCK
 	  support. This provides a block device driver, which you can use
 	  to mount the filesystem. Almost everyone wishing MemoryStick
 	  support should say Y or M here.
+
+config MS_BLOCK
+	tristate "MemoryStick Standard device driver"
+	depends on BLOCK && EXPERIMENTAL
+	help
+	  Say Y here to enable the MemoryStick Standard device driver
+	  support. This provides a block device driver, which you can use
+	  to mount the filesystem.
+	  This driver works with old (bulky) MemoryStick and MemoryStick Duo
+	  but not PRO. Say Y if you have such card.
+	  Driver is new and not yet well tested, thus it can damage your card
+	  (even permanently)
drivers/memstick/core/Makefile +1 -1
index 8b2b529..19d960b 100644
@@ -7,5 +7,5 @@ ifeq ($(CONFIG_MEMSTICK_DEBUG),y)
 endif
 
 obj-$(CONFIG_MEMSTICK)		+= memstick.o
-
+obj-$(CONFIG_MS_BLOCK)		+= ms_block.o
 obj-$(CONFIG_MSPRO_BLOCK)	+= mspro_block.o
drivers/memstick/core/ms_block.c new file +2285 -0

2,285 lines not on this page · raw message

drivers/memstick/core/ms_block.h new file +245 -0

245 lines not on this page · raw message

Signature · 1 line
1.7.1
author maintainer
#10 lore raw

PATCH v2 4/4 memstick: add Alex Dubov to MAINTAINERS of the memstick core

In reply to Maxim Levitsky

This code is supposed to be maintained by him and unless he doesn't want to do so, MAINTAINERS should reflect the state of things, and bugreporters should know whom to blame for bugs.

---
 MAINTAINERS |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
MAINTAINERS +12 -1
index c9293f7..8687ba1 100644
@@ -5614,7 +5614,18 @@ F:	drivers/char/sonypi.c
 F:	drivers/platform/x86/sony-laptop.c
 F:	include/linux/sony-laptop.h
 
-SONY MEMORYSTICK CARD SUPPORT
+SONY MEMORYSTICK SUBSYSTEM
+M:	Alex Dubov <[email protected]>
+S:	Maintained
+F:	drivers/memstick/memstick.c
+F:	drivers/memstick/mspro_block.c
+
+SONY MEMORYSTICK DRIVER FOR JMICRON CONTROLLERS
+M:	Alex Dubov <[email protected]>
+S:	Maintained
+F:	drivers/memstick/host/jmb38x_ms.c
+
+SONY MEMORYSTICK DRIVER FOR TI CONTROLLERS
 M:	Alex Dubov <[email protected]>
 W:	http://tifmxx.berlios.de/
 S:	Maintained
Signature · 1 line
1.7.1