Skip to contentSkip to conversation

PCI: Convert pdev_sort_resources() to use resource name helper

PATCH In review Ilpo Järvinen 2 participants 6 messages Oct 16, 2024 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: Convert pdev_sort_resources() to use resource name helper

Use pci_resource_name() helper in pdev_sort_resources() to print resources in user-friendly format.

---
 drivers/pci/setup-bus.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/pci/setup-bus.c +3 -2
index 23082bc0ca37..071c5436b4a5 100644
@@ -134,6 +134,7 @@ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head)
 	int i;
 
 	pci_dev_for_each_resource(dev, r, i) {
+		const char *r_name = pci_resource_name(dev, i);
 		struct pci_dev_resource *dev_res, *tmp;
 		resource_size_t r_align;
 		struct list_head *n;
@@ -146,8 +147,8 @@ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head)
 
 		r_align = pci_resource_alignment(dev, r);
 		if (!r_align) {
-			pci_warn(dev, "BAR %d: %pR has bogus alignment\n",
-				 i, r);
+			pci_warn(dev, "%s: %pR has bogus alignment\n",
+				 r_name, r);
 			continue;
 		}
 
Signature · 1 line
2.39.5
#1 lore raw
Quoted 31 lines · Ilpo Järvinen

Use pci_resource_name() helper in pdev_sort_resources() to print resources in user-friendly format.

---
 drivers/pci/setup-bus.c | 5 +++--

 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/pci/setup-bus.c +0 -0
index 23082bc0ca37..071c5436b4a5 100644
@@ -134,6 +134,7 @@ static void pdev_sort_resources(struct pci_dev
 *dev, struct list_head *head)
  	int i;


  pci_dev_for_each_resource(dev, r, i) {

drivers/pci/setup-bus.c +1 -0
+		const char *r_name = pci_resource_name(dev, i);

  struct pci_dev_resource *dev_res, *tmp; resource_size_t r_align; struct list_head *n;

drivers/pci/setup-bus.c +0 -0
@@ -146,8 +147,8 @@ static void pdev_sort_resources(struct pci_dev
 *dev, struct list_head *head)


  r_align = pci_resource_alignment(dev, r); if (!r_align) {

drivers/pci/setup-bus.c +0 -1
-			pci_warn(dev, "BAR %d: %pR has bogus

alignment\n",

drivers/pci/setup-bus.c +1 -1
-				 i, r);
+			pci_warn(dev, "%s: %pR has bogus

alignment\n",

drivers/pci/setup-bus.c static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) · line 151

Quoted 1 line
drivers/pci/setup-bus.c +1 -0
+				 r_name, r);

Why do you remove the BAR index number, don't you think this information is also useful?

One could also consider printing r_align, would that be useful? Note that there is a similar pci_warn down below in line 1118 that does print it. Would you want to change that pci_warn()-string, too?

P.

Quoted 3 lines

  continue;
  }

#2 lore raw
Quoted 28 lines · Philipp Stanner
Quoted 27 lines · Ilpo Järvinen

Use pci_resource_name() helper in pdev_sort_resources() to print resources in user-friendly format.

---
 drivers/pci/setup-bus.c | 5 +++--

 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/pci/setup-bus.c +0 -0
index 23082bc0ca37..071c5436b4a5 100644
@@ -134,6 +134,7 @@ static void pdev_sort_resources(struct pci_dev
 *dev, struct list_head *head)
  	int i;


  pci_dev_for_each_resource(dev, r, i) {

drivers/pci/setup-bus.c +1 -0
+		const char *r_name = pci_resource_name(dev, i);

  struct pci_dev_resource *dev_res, *tmp; resource_size_t r_align; struct list_head *n;

drivers/pci/setup-bus.c +0 -0
@@ -146,8 +147,8 @@ static void pdev_sort_resources(struct pci_dev
 *dev, struct list_head *head)


  r_align = pci_resource_alignment(dev, r); if (!r_align) {

drivers/pci/setup-bus.c +0 -1
-			pci_warn(dev, "BAR %d: %pR has bogus
Quoted 8 lines

drivers/pci/setup-bus.c static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) · line 151

Quoted 5 lines

alignment\n",

drivers/pci/setup-bus.c +1 -1
-				 i, r);
+			pci_warn(dev, "%s: %pR has bogus

alignment\n",

drivers/pci/setup-bus.c +1 -0
+				 r_name, r);

Why do you remove the BAR index number, don't you think this information is also useful?

That's because of how pci_resource_name() works. The number will be included in the returned string and it won't be always same as i. So that change is done on purpose.

Quoted 1 line

One could also consider printing r_align, would that be useful?

As per the preceeding condition, it's known to be zero so it's not that useful for any developer looking at these code lines.

Quoted 3 lines

Note
that there is a similar pci_warn down below in line 1118 that does print it. Would you want to change that pci_warn()-string, too?

pci_warn() on line 1118 does NOT print i (as expected when using pci_resource_name()) and there align is not zero so I don't see how this is relevant.

But thanks for taking a look anyway. :-)

Signature · 1 line
 i.
#3 lore raw
Quoted 39 lines · Ilpo Järvinen
Quoted 28 lines · Philipp Stanner
Quoted 27 lines · Ilpo Järvinen

Use pci_resource_name() helper in pdev_sort_resources() to print resources in user-friendly format.

---
 drivers/pci/setup-bus.c | 5 +++--

 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/pci/setup-bus.c +0 -0
index 23082bc0ca37..071c5436b4a5 100644
@@ -134,6 +134,7 @@ static void pdev_sort_resources(struct pci_dev
 *dev, struct list_head *head)
  	int i;


  pci_dev_for_each_resource(dev, r, i) {

drivers/pci/setup-bus.c +1 -0
+		const char *r_name = pci_resource_name(dev, i);

  struct pci_dev_resource *dev_res, *tmp; resource_size_t r_align; struct list_head *n;

drivers/pci/setup-bus.c +0 -0
@@ -146,8 +147,8 @@ static void pdev_sort_resources(struct pci_dev
 *dev, struct list_head *head)


  r_align = pci_resource_alignment(dev, r); if (!r_align) {

drivers/pci/setup-bus.c +0 -1
-			pci_warn(dev, "BAR %d: %pR has bogus
Quoted 8 lines

drivers/pci/setup-bus.c static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) · line 151

Quoted 5 lines

alignment\n",

drivers/pci/setup-bus.c +1 -1
-				 i, r);
+			pci_warn(dev, "%s: %pR has bogus

alignment\n",

drivers/pci/setup-bus.c +1 -0
+				 r_name, r);

Why do you remove the BAR index number, don't you think this information is also useful?

Quoted 3 lines

That's because of how pci_resource_name() works. The number will be included in the returned string and it won't be always same as i. So that change is done on purpose.

That being said, I now realize the other examples use the colon differently "%s %pR: ..." so I'll change that for v2.

Signature · 1 line
 i.
Quoted 16 lines
Quoted 1 line

One could also consider printing r_align, would that be useful?

As per the preceeding condition, it's known to be zero so it's not that useful for any developer looking at these code lines.

Quoted 3 lines

Note
that there is a similar pci_warn down below in line 1118 that does print it. Would you want to change that pci_warn()-string, too?

pci_warn() on line 1118 does NOT print i (as expected when using pci_resource_name()) and there align is not zero so I don't see how this is relevant.

But thanks for taking a look anyway. :-)

#4 lore raw
In reply to Ilpo Järvinen
Quoted 41 lines · Ilpo Järvinen
Quoted 30 lines · Philipp Stanner
Quoted 29 lines · Ilpo Järvinen

Use pci_resource_name() helper in pdev_sort_resources() to print resources in user-friendly format.

---
 drivers/pci/setup-bus.c | 5 +++--

 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/pci/setup-bus.c +0 -0
index 23082bc0ca37..071c5436b4a5 100644
@@ -134,6 +134,7 @@ static void pdev_sort_resources(struct

pci_dev
*dev, struct list_head *head)
  int i;

  pci_dev_for_each_resource(dev, r, i) {

drivers/pci/setup-bus.c +1 -0
+		const char *r_name = pci_resource_name(dev, i);

  struct pci_dev_resource *dev_res, *tmp; resource_size_t r_align; struct list_head *n;

drivers/pci/setup-bus.c +0 -0
@@ -146,8 +147,8 @@ static void pdev_sort_resources(struct

pci_dev
*dev, struct list_head *head)

  r_align = pci_resource_alignment(dev, r); if (!r_align) {

drivers/pci/setup-bus.c +0 -1
-			pci_warn(dev, "BAR %d: %pR has bogus
Quoted 8 lines

drivers/pci/setup-bus.c static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) · line 151

Quoted 5 lines

alignment\n",

drivers/pci/setup-bus.c +1 -1
-				 i, r);
+			pci_warn(dev, "%s: %pR has bogus

alignment\n",

drivers/pci/setup-bus.c +1 -0
+				 r_name, r);

Why do you remove the BAR index number, don't you think this information is also useful?

Quoted 8 lines

That's because of how pci_resource_name() works. The number will be included in the returned string and it won't be always same as i. So that change is done on purpose.

Quoted 1 line

One could also consider printing r_align, would that be useful?

As per the preceeding condition, it's known to be zero so it's not that useful for any developer looking at these code lines.

Ah, right. Would it then make sense then to do:

pci_warn(dev, "%s: %pR: Alignment must not be zero.\n", ...);

Would tell then exactly what the problem is. Unless the devs know that a bogus alignment is definitely always 0.

?

Quoted 11 lines
Quoted 4 lines

Note
that there is a similar pci_warn down below in line 1118 that does print it. Would you want to change that pci_warn()-string, too?

pci_warn() on line 1118 does NOT print i (as expected when using pci_resource_name()) and there align is not zero so I don't see how this
is relevant.

But thanks for taking a look anyway. :-)

Sure thing

Quoted 1 line
#5 lore raw
Quoted 51 lines · Philipp Stanner
Quoted 41 lines · Ilpo Järvinen
Quoted 30 lines · Philipp Stanner
Quoted 29 lines · Ilpo Järvinen

Use pci_resource_name() helper in pdev_sort_resources() to print resources in user-friendly format.

---
 drivers/pci/setup-bus.c | 5 +++--

 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/pci/setup-bus.c +0 -0
index 23082bc0ca37..071c5436b4a5 100644
@@ -134,6 +134,7 @@ static void pdev_sort_resources(struct

pci_dev
*dev, struct list_head *head)
  int i;

  pci_dev_for_each_resource(dev, r, i) {

drivers/pci/setup-bus.c +1 -0
+		const char *r_name = pci_resource_name(dev, i);

  struct pci_dev_resource *dev_res, *tmp; resource_size_t r_align; struct list_head *n;

drivers/pci/setup-bus.c +0 -0
@@ -146,8 +147,8 @@ static void pdev_sort_resources(struct

pci_dev
*dev, struct list_head *head)

  r_align = pci_resource_alignment(dev, r); if (!r_align) {

drivers/pci/setup-bus.c +0 -1
-			pci_warn(dev, "BAR %d: %pR has bogus
Quoted 8 lines

drivers/pci/setup-bus.c static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) · line 151

Quoted 5 lines

alignment\n",

drivers/pci/setup-bus.c +1 -1
-				 i, r);
+			pci_warn(dev, "%s: %pR has bogus

alignment\n",

drivers/pci/setup-bus.c +1 -0
+				 r_name, r);

Why do you remove the BAR index number, don't you think this information is also useful?

Quoted 8 lines

That's because of how pci_resource_name() works. The number will be included in the returned string and it won't be always same as i. So that change is done on purpose.

Quoted 1 line

One could also consider printing r_align, would that be useful?

As per the preceeding condition, it's known to be zero so it's not that useful for any developer looking at these code lines.

Quoted 8 lines

Ah, right. Would it then make sense then to do:

pci_warn(dev, "%s: %pR: Alignment must not be zero.\n", ...);

Would tell then exactly what the problem is. Unless the devs know that a bogus alignment is definitely always 0.

?

While I personally don't need that given the surrounding code, I can change the string to be more precise. Thanks.

Signature · 1 line
 i.