Patchwork [5/5] libata: Clarify ata_set_lba_range_entries function

login
register
mail settings
Submitter Martin K. Petersen
Date Nov. 26, 2009, 5 p.m.
Message ID <1259254843-8326-6-git-send-email-martin.petersen@oracle.com>
Download mbox | patch
Permalink /patch/39567/
State Not Applicable
Delegated to: David Miller
Headers show

Comments

Martin K. Petersen - Nov. 26, 2009, 5 p.m.
ata_set_lba_range_entries used the variable max for two different things
which was confusing.  Make the function take a buffer size in bytes as
argument and return the used buffer size upon completion.

Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
---
 drivers/ata/libata-scsi.c |    2 +-
 include/linux/ata.h       |   20 ++++++++++----------
 2 files changed, 11 insertions(+), 11 deletions(-)
Jeff Garzik - Dec. 3, 2009, 11:02 p.m.
On 11/26/2009 12:00 PM, Martin K. Petersen wrote:
> ata_set_lba_range_entries used the variable max for two different things
> which was confusing.  Make the function take a buffer size in bytes as
> argument and return the used buffer size upon completion.
>
> Signed-off-by: Martin K. Petersen<martin.petersen@oracle.com>
> ---
>   drivers/ata/libata-scsi.c |    2 +-
>   include/linux/ata.h       |   20 ++++++++++----------
>   2 files changed, 11 insertions(+), 11 deletions(-)

applied


--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 08d4ab7..e06ee7b 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -2973,7 +2973,7 @@  static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc)
 		goto invalid_fld;
 
 	buf = page_address(sg_page(scsi_sglist(scmd)));
-	size = ata_set_lba_range_entries(buf, 512 / 8, block, n_block);
+	size = ata_set_lba_range_entries(buf, 512, block, n_block);
 
 	tf->protocol = ATA_PROT_DMA;
 	tf->hob_feature = 0;
diff --git a/include/linux/ata.h b/include/linux/ata.h
index b18b2bb..54a8ffb 100644
--- a/include/linux/ata.h
+++ b/include/linux/ata.h
@@ -981,17 +981,17 @@  static inline void ata_id_to_hd_driveid(u16 *id)
 }
 
 /*
- * Write up to 'max' LBA Range Entries to the buffer that will cover the
- * extent from sector to sector + count.  This is used for TRIM and for
- * ADD LBA(S) TO NV CACHE PINNED SET.
+ * Write LBA Range Entries to the buffer that will cover the extent from
+ * sector to sector + count.  This is used for TRIM and for ADD LBA(S)
+ * TO NV CACHE PINNED SET.
  */
-static inline unsigned ata_set_lba_range_entries(void *_buffer, unsigned max,
-						u64 sector, unsigned long count)
+static inline unsigned ata_set_lba_range_entries(void *_buffer,
+		unsigned buf_size, u64 sector, unsigned long count)
 {
 	__le64 *buffer = _buffer;
-	unsigned i = 0;
+	unsigned i = 0, used_bytes;
 
-	while (i < max) {
+	while (i < buf_size / 8 ) { /* 6-byte LBA + 2-byte range per entry */
 		u64 entry = sector |
 			((u64)(count > 0xffff ? 0xffff : count) << 48);
 		buffer[i++] = __cpu_to_le64(entry);
@@ -1001,9 +1001,9 @@  static inline unsigned ata_set_lba_range_entries(void *_buffer, unsigned max,
 		sector += 0xffff;
 	}
 
-	max = ALIGN(i * 8, 512);
-	memset(buffer + i, 0, max - i * 8);
-	return max;
+	used_bytes = ALIGN(i * 8, 512);
+	memset(buffer + i, 0, used_bytes - i * 8);
+	return used_bytes;
 }
 
 static inline int is_multi_taskfile(struct ata_taskfile *tf)