Skip to contentSkip to conversation

drivers: block: save return value of pci_find_capability() in u8

PATCH In review Puranjay Mohan 8 participants 13 messages Dec 6, 2020 – Dec 7, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: block: save return value of pci_find_capability() in u8

Callers of pci_find_capability should save the return value in u8. change type of variables from int to u8 to match the specification.

---
 drivers/block/mtip32xx/mtip32xx.c | 2 +-
 drivers/block/skd_main.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +1 -1
index 153e2cdecb4d..da57d37c6d20 100644
@@ -3936,7 +3936,7 @@ static DEFINE_HANDLER(7);
 
 static void mtip_disable_link_opts(struct driver_data *dd, struct pci_dev *pdev)
 {
-	int pos;
+	u8 pos;
 	unsigned short pcie_dev_ctrl;
 
 	pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
drivers/block/skd_main.c +1 -1
index a962b4551bed..16d59569129b 100644
@@ -3136,7 +3136,7 @@ MODULE_DEVICE_TABLE(pci, skd_pci_tbl);
 
 static char *skd_pci_info(struct skd_device *skdev, char *str)
 {
-	int pcie_reg;
+	u8 pcie_reg;
 
 	strcpy(str, "PCIe (");
 	pcie_reg = pci_find_capability(skdev->pdev, PCI_CAP_ID_EXP);
Signature · 1 line
2.27.0
#1 lore raw
Quoted 2 lines · Puranjay Mohan

Callers of pci_find_capability should save the return value in u8. change type of variables from int to u8 to match the specification.

I did not understand this, pci_find_capability() does not return u8.

what is it that we are achieving by changing the variable type ?

This patch will probably also generate type mismatch warning with

certain static analyzers.

Quoted 32 lines
---
 drivers/block/mtip32xx/mtip32xx.c | 2 +-
 drivers/block/skd_main.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +1 -1
index 153e2cdecb4d..da57d37c6d20 100644
@@ -3936,7 +3936,7 @@ static DEFINE_HANDLER(7);
 
 static void mtip_disable_link_opts(struct driver_data *dd, struct pci_dev *pdev)
 {
-	int pos;
+	u8 pos;
 	unsigned short pcie_dev_ctrl;
 
 	pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
drivers/block/skd_main.c +1 -1
index a962b4551bed..16d59569129b 100644
@@ -3136,7 +3136,7 @@ MODULE_DEVICE_TABLE(pci, skd_pci_tbl);
 
 static char *skd_pci_info(struct skd_device *skdev, char *str)
 {
-	int pcie_reg;
+	u8 pcie_reg;
 
 	strcpy(str, "PCIe (");
 	pcie_reg = pci_find_capability(skdev->pdev, PCI_CAP_ID_EXP);
#2 lore raw
Quoted 11 lines · Chaitanya Kulkarni
Quoted 2 lines · Puranjay Mohan

Callers of pci_find_capability should save the return value in u8. change type of variables from int to u8 to match the specification.

I did not understand this, pci_find_capability() does not return u8.

what is it that we are achieving by changing the variable type ?

This patch will probably also generate type mismatch warning with

certain static analyzers.

There's a patch pending via the PCI tree to change the return type to u8. We can do one of:

- Ignore this. It only changes something on the stack, so no real space saving and there's no problem assigning the u8 return value to the "int".

- The maintainer could ack it and I could merge it via the PCI tree so it happens in the correct order (after the interface change).

- The PCI core interface change will be merged for v5.11, so we could hold this until v5.12.

I don't really have a preference. The only place there would really be a benefit would be if we store the return value in a struct, where we could potentially save three bytes.

Bjorn

Quoted 34 lines
Quoted 32 lines
---
 drivers/block/mtip32xx/mtip32xx.c | 2 +-
 drivers/block/skd_main.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +1 -1
index 153e2cdecb4d..da57d37c6d20 100644
@@ -3936,7 +3936,7 @@ static DEFINE_HANDLER(7);
 
 static void mtip_disable_link_opts(struct driver_data *dd, struct pci_dev *pdev)
 {
-	int pos;
+	u8 pos;
 	unsigned short pcie_dev_ctrl;
 
 	pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
drivers/block/skd_main.c +1 -1
index a962b4551bed..16d59569129b 100644
@@ -3136,7 +3136,7 @@ MODULE_DEVICE_TABLE(pci, skd_pci_tbl);
 
 static char *skd_pci_info(struct skd_device *skdev, char *str)
 {
-	int pcie_reg;
+	u8 pcie_reg;
 
 	strcpy(str, "PCIe (");
 	pcie_reg = pci_find_capability(skdev->pdev, PCI_CAP_ID_EXP);
#3 lore raw
Quoted 16 lines · Bjorn Helgaas
Quoted 11 lines · Chaitanya Kulkarni
Quoted 2 lines · Puranjay Mohan

Callers of pci_find_capability should save the return value in u8. change type of variables from int to u8 to match the specification.

I did not understand this, pci_find_capability() does not return u8.

what is it that we are achieving by changing the variable type ?

This patch will probably also generate type mismatch warning with

certain static analyzers.

There's a patch pending via the PCI tree to change the return type to u8. We can do one of:

Quoted 6 lines

- Ignore this. It only changes something on the stack, so no real space saving and there's no problem assigning the u8 return value to the "int".

- The maintainer could ack it and I could merge it via the PCI tree so it happens in the correct order (after the interface change).

That works for me. But this driver changes generally go through Jens block tree.

Jens,

Is this OK with you if Bjorn takes the patch through the PCI tree ?

Quoted 45 lines

- The PCI core interface change will be merged for v5.11, so we could hold this until v5.12.

I don't really have a preference. The only place there would really be a benefit would be if we store the return value in a struct, where we could potentially save three bytes.

Bjorn

Quoted 34 lines
Quoted 32 lines
---
 drivers/block/mtip32xx/mtip32xx.c | 2 +-
 drivers/block/skd_main.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +1 -1
index 153e2cdecb4d..da57d37c6d20 100644
@@ -3936,7 +3936,7 @@ static DEFINE_HANDLER(7);
 
 static void mtip_disable_link_opts(struct driver_data *dd, struct pci_dev *pdev)
 {
-	int pos;
+	u8 pos;
 	unsigned short pcie_dev_ctrl;
 
 	pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
drivers/block/skd_main.c +1 -1
index a962b4551bed..16d59569129b 100644
@@ -3136,7 +3136,7 @@ MODULE_DEVICE_TABLE(pci, skd_pci_tbl);
 
 static char *skd_pci_info(struct skd_device *skdev, char *str)
 {
-	int pcie_reg;
+	u8 pcie_reg;
 
 	strcpy(str, "PCIe (");
 	pcie_reg = pci_find_capability(skdev->pdev, PCI_CAP_ID_EXP);
Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer
#4 lore raw
Quoted 21 lines · Damien Le Moal
Quoted 20 lines · Bjorn Helgaas
Quoted 11 lines · Chaitanya Kulkarni
Quoted 2 lines · Puranjay Mohan

Callers of pci_find_capability should save the return value in u8. change type of variables from int to u8 to match the specification.

I did not understand this, pci_find_capability() does not return u8.

what is it that we are achieving by changing the variable type ?

This patch will probably also generate type mismatch warning with

certain static analyzers.

There's a patch pending via the PCI tree to change the return type to u8. We can do one of:

- Ignore this. It only changes something on the stack, so no real space saving and there's no problem assigning the u8 return value to the "int".

Quoted 8 lines
Quoted 2 lines

- The maintainer could ack it and I could merge it via the PCI tree so it happens in the correct order (after the interface change).

That works for me. But this driver changes generally go through Jens block tree.

Jens,

Is this OK with you if Bjorn takes the patch through the PCI tree ?

Yep that's fine, if that makes it easier to handle.

Signature · 1 line
Jens Axboe
Reviewed-by
#5 lore raw
In reply to Bjorn Helgaas

Bjorn,

Quoted 2 lines · Bjorn Helgaas

There's a patch pending via the PCI tree to change the return type to u8. We can do one of:

I did not know about the pending patch, if that is going to change the return

type then this patch makes sense.

Quoted 6 lines

- Ignore this. It only changes something on the stack, so no real space saving and there's no problem assigning the u8 return value to the "int".
- The maintainer could ack it and I could merge it via the PCI tree so it happens in the correct order (after the interface change).

If we want it in 5.11 then I think PCI tree is a right way go about it.

Quoted 5 lines

- The PCI core interface change will be merged for v5.11, so we could hold this until v5.12.
I don't really have a preference. The only place there would really be a benefit would be if we store the return value in a struct, where we could potentially save three bytes.

Totally agree.

Quoted 1 line

Bjorn

Whoever is going to apply please add :-

#6 lore raw
In reply to Bjorn Helgaas
Quoted 11 lines · Bjorn Helgaas
Quoted 10 lines · Chaitanya Kulkarni
Quoted 2 lines · Puranjay Mohan

Callers of pci_find_capability should save the return value in u8. change type of variables from int to u8 to match the specification.the com

I did not understand this, pci_find_capability() does not return u8.

what is it that we are achieving by changing the variable type ?

This patch will probably also generate type mismatch warning with

Quoted 8 lines
Quoted 1 line

certain static analyzers.

There's a patch pending via the PCI tree to change the return type to u8. We can do one of:

- Ignore this. It only changes something on the stack, so no real space saving and there's no problem assigning the u8 return value to the "int".

I seem to remember some compilers would emit a sequence to constrain the result to a valid char, but that looks like it is fixed in gcc-9 if the input was also u8

Signature · 4 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html
Acked-by on v1 1/1
#7 lore raw
In reply to Puranjay Mohan
Quoted 28 lines · Puranjay Mohan

Callers of pci_find_capability should save the return value in u8. change type of variables from int to u8 to match the specification.

---
 drivers/block/mtip32xx/mtip32xx.c | 2 +-
 drivers/block/skd_main.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +1 -1
index 153e2cdecb4d..da57d37c6d20 100644
@@ -3936,7 +3936,7 @@ static DEFINE_HANDLER(7);
 
 static void mtip_disable_link_opts(struct driver_data *dd, struct pci_dev *pdev)
 {
-	int pos;
+	u8 pos;
 	unsigned short pcie_dev_ctrl;
 
 	pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
drivers/block/skd_main.c +0 -0
index a962b4551bed..16d59569129b 100644

drivers/block/skd_main.c MODULE_DEVICE_TABLE(pci, skd_pci_tbl); · line 3142

Quoted 8 lines
drivers/block/skd_main.c +1 -1
@@ -3136,7 +3136,7 @@ MODULE_DEVICE_TABLE(pci, skd_pci_tbl);
 
 static char *skd_pci_info(struct skd_device *skdev, char *str)
 {
-	int pcie_reg;
+	u8 pcie_reg;
 
 	strcpy(str, "PCIe (");
 	pcie_reg = pci_find_capability(skdev->pdev, PCI_CAP_ID_EXP);
Signature · 2 lines
Damien Le Moal
Western Digital Research
#8 lore raw
In reply to Puranjay Mohan

Can we take a step back? I think in general drivers should not bother with pci_find_capability. Both mtip32xx and skd want to find out if the devices are PCIe devices, skd then just prints the link speed for which we have much better helpers, mtip32xx than messes with DEVCTL which seems actively dangerous to me.

#9 lore raw
Quoted 5 lines · Christoph Hellwig

Can we take a step back? I think in general drivers should not bother with pci_find_capability. Both mtip32xx and skd want to find out if the devices are PCIe devices, skd then just prints the link speed for which we have much better helpers, mtip32xx than messes with DEVCTL which seems actively dangerous to me.

Yes, that's a much better idea. Plus it would be a much more interesting mentorship project.

#10 lore raw
In reply to Christoph Hellwig
Quoted 6 lines · Christoph Hellwig

Can we take a step back? I think in general drivers should not bother with pci_find_capability. Both mtip32xx and skd want to find out if the devices are PCIe devices, skd then just prints the link speed for which we have much better helpers, mtip32xx than messes with DEVCTL which seems actively dangerous to me.

The skd driver uses pci_find_capability(skdev->pdev, PCI_CAP_ID_EXP); to check if the device is PCIe, it can use pci_is_pcie() to do that. After that it uses pci_read_config_word(skdev->pdev, pcie_reg, &pcie_lstat); to read the Link Status Register, I think
it should use pcie_capability_read_word(skdev->pdev, PCI_EXP_LNKSTA, &pcie_lstat);

Please let me know if the above changes are correct so I may send a patch.

Signature · 5 lines
Thanks and Regards

Yours Truly,

Puranjay Mohan
#11 lore raw
Quoted 8 lines · Puranjay Mohan
Quoted 6 lines · Christoph Hellwig

Can we take a step back? I think in general drivers should not bother with pci_find_capability. Both mtip32xx and skd want to find out if the devices are PCIe devices, skd then just prints the link speed for which we have much better helpers, mtip32xx than messes with DEVCTL which seems actively dangerous to me.

Quoted 8 lines

The skd driver uses pci_find_capability(skdev->pdev, PCI_CAP_ID_EXP); to check if the device is PCIe, it can use pci_is_pcie() to do that. After that it uses pci_read_config_word(skdev->pdev, pcie_reg, &pcie_lstat); to read the Link Status Register, I think
it should use pcie_capability_read_word(skdev->pdev, PCI_EXP_LNKSTA, &pcie_lstat);

Please let me know if the above changes are correct so I may send a patch.

You just want to print the current link speed, right? Does skdev->pdev->bus->cur_bus_speed provide what you need?

#12 lore raw
Quoted 17 lines · Keith Busch
Quoted 15 lines · Puranjay Mohan
Quoted 6 lines · Christoph Hellwig

Can we take a step back? I think in general drivers should not bother with pci_find_capability. Both mtip32xx and skd want to find out if the devices are PCIe devices, skd then just prints the link speed for which we have much better helpers, mtip32xx than messes with DEVCTL which seems actively dangerous to me.

The skd driver uses pci_find_capability(skdev->pdev, PCI_CAP_ID_EXP); to check if the device is PCIe, it can use pci_is_pcie() to do that. After that it uses pci_read_config_word(skdev->pdev, pcie_reg, &pcie_lstat); to read the Link Status Register, I think
it should use pcie_capability_read_word(skdev->pdev, PCI_EXP_LNKSTA, &pcie_lstat);

Quoted 4 lines
Quoted 1 line

Please let me know if the above changes are correct so I may send a patch.

You just want to print the current link speed, right? Does skdev->pdev->bus->cur_bus_speed provide what you need?

After discussing with Bjorn, we concluded that we don't need to print the speed as it is already printed by the PCI core for every device. PCI core calls __pcie_print_link_status() for every device, and hence the skd_pci_info() is redundant and can be removed?

Signature · 5 lines
Thanks and Regards

Yours Truly,

Puranjay Mohan