Skip to contentSkip to conversation

lightnvm: change max_phys_sect to ushort

PATCH Superseded Matias Bjørling 4 participants 7 messages Nov 12, 2015 – Nov 16, 2015

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lightnvm: change max_phys_sect to ushort

The max_phys_sect variable is defined as a char. We do a boundary check to maximally allow 256 physical page descriptors per command. As we are not indexing from zero. This expression is always in false. Bump the max_phys_sect to an unsigned short to support the range check.

---
 include/linux/lightnvm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/lightnvm.h +1 -1
index 69c9057..4b1cd3d 100644
@@ -220,7 +220,7 @@ struct nvm_dev_ops {
 	nvm_dev_dma_alloc_fn	*dev_dma_alloc;
 	nvm_dev_dma_free_fn	*dev_dma_free;
 
-	uint8_t			max_phys_sect;
+	unsigned int max_phys_sect;
 };
 
 struct nvm_lun {
Signature · 1 line
2.1.4
#1 lore raw
Quoted 4 lines · Matias Bjørling

The max_phys_sect variable is defined as a char. We do a boundary check to maximally allow 256 physical page descriptors per command. As we are not indexing from zero. This expression is always in false. Bump the max_phys_sect to an unsigned short to support the range check.

unsigned int?

Quoted 12 lines
---
 include/linux/lightnvm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/lightnvm.h +0 -0
index 69c9057..4b1cd3d 100644

include/linux/lightnvm.h struct nvm_dev_ops { · line 223

Quoted 5 lines
include/linux/lightnvm.h +1 -1
@@ -220,7 +220,7 @@ struct nvm_dev_ops {
        nvm_dev_dma_alloc_fn    *dev_dma_alloc;
        nvm_dev_dma_free_fn     *dev_dma_free;
 
-       uint8_t                 max_phys_sect;
+       unsigned int max_phys_sect;

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#2 lore raw
Quoted 7 lines · Geert Uytterhoeven
Quoted 4 lines · Matias Bjørling

The max_phys_sect variable is defined as a char. We do a boundary check to maximally allow 256 physical page descriptors per command. As we are not indexing from zero. This expression is always in false. Bump the max_phys_sect to an unsigned short to support the range check.

unsigned int?

Grah, I need to be more careful. I sent the wrong patch after I had fixed it to unsigned short.

#3 lore raw
Quoted 3 lines · Matias Bjørling

Grah, I need to be more careful. I sent the wrong patch after I had fixed it to unsigned short.

Actually, I think "unsigned int" was better.

You're not saving any space with "unsigned short" (the size of the structure will be rounded up to the alignment of it anyway), and we should generally strive to avoid 16-bit accesses unless there is some real reason for them, because they are often slower than either "char" or "int". Several architectures have weak support for 16-bit accesses (eg alpha), and even on x86 you end up having operand size overrides etc.

So unless there is a clear *reason* to use "short" - just don't.

Linus

#4 lore raw
Quoted 7 lines · Linus Torvalds
Quoted 3 lines · Matias Bjørling

Grah, I need to be more careful. I sent the wrong patch after I had fixed it to unsigned short.

Actually, I think "unsigned int" was better.

Quoted 8 lines

You're not saving any space with "unsigned short" (the size of the structure will be rounded up to the alignment of it anyway), and we should generally strive to avoid 16-bit accesses unless there is some real reason for them, because they are often slower than either "char" or "int". Several architectures have weak support for 16-bit accesses (eg alpha), and even on x86 you end up having operand size overrides etc.

Thanks

Quoted 4 lines

So unless there is a clear *reason* to use "short" - just don't.

Linus

#5 lore raw
In reply to Matias Bjørling
Quoted 5 lines · Matias Bjørling

The max_phys_sect variable is defined as a char. We do a boundary check to maximally allow 256 physical page descriptors per command. As we are not indexing from zero. This expression is always in false. Bump the max_phys_sect to an unsigned short to support the range check.

You might have to change the commit message to match the code change. s/unsigned short/unsigned int. RIght?

Quoted 19 lines
---
 include/linux/lightnvm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/lightnvm.h +1 -1
index 69c9057..4b1cd3d 100644
@@ -220,7 +220,7 @@ struct nvm_dev_ops {
        nvm_dev_dma_alloc_fn    *dev_dma_alloc;
        nvm_dev_dma_free_fn     *dev_dma_free;
 
-       uint8_t                 max_phys_sect;
+       unsigned int max_phys_sect;
 };
 
 struct nvm_lun {
Signature · 1 line
Thiago Farina
#6 lore raw
Quoted 8 lines · Thiago Farina
Quoted 5 lines · Matias Bjørling

The max_phys_sect variable is defined as a char. We do a boundary check to maximally allow 256 physical page descriptors per command. As we are not indexing from zero. This expression is always in false. Bump the max_phys_sect to an unsigned short to support the range check.

You might have to change the commit message to match the code change. s/unsigned short/unsigned int. RIght?

You're right. It has been fixed.

Quoted 22 lines
Quoted 20 lines
---
  include/linux/lightnvm.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/lightnvm.h +1 -1
index 69c9057..4b1cd3d 100644
@@ -220,7 +220,7 @@ struct nvm_dev_ops {
         nvm_dev_dma_alloc_fn    *dev_dma_alloc;
         nvm_dev_dma_free_fn     *dev_dma_free;
 
-       uint8_t                 max_phys_sect;
+       unsigned int max_phys_sect;
  };
 
  struct nvm_lun {