Skip to contentSkip to conversation

gpib: mark pnp_device_id tables as __maybe_unused

PATCH In review Arnd Bergmann 3 participants 4 messages Feb 5, 2025 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpib: mark pnp_device_id tables as __maybe_unused

From: Arnd Bergmann <[email protected]>

This variable is not referenced in either of these two drivers driver, causing a warning when they are built-in and W=1 warnings are enabled with gcc:

drivers/staging/gpib/tnt4882/tnt4882_gpib.c:1507:35: error: 'tnt4882_pnp_table' defined but not used [-Werror=unused-const-variable=]

 1507 | static const struct pnp_device_id tnt4882_pnp_table[] = {
      |                                   ^~~~~~~~~~~~~~~~~

drivers/staging/gpib/hp_82341/hp_82341.c:811:35: error: 'hp_82341_pnp_table' defined but not used [-Werror=unused-const-variable=]
811 | static const struct pnp_device_id hp_82341_pnp_table[] = {

The MODULE_DEVICE_TABLE() entry does have the effect of loading the module when the PNP device is detected, so it is still needed for the modular case.

Ideally the drivers should be converted to pnp_register_driver(), which would lead to the ID table actually being used.

As a simpler workaround, add a __maybe_unused annotation to shut up the warning.

---
 drivers/staging/gpib/hp_82341/hp_82341.c    | 2 +-
 drivers/staging/gpib/tnt4882/tnt4882_gpib.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/gpib/hp_82341/hp_82341.c +1 -1
index 800f99c05566..7284311e04e2 100644
@@ -808,7 +808,7 @@ static void hp_82341_detach(gpib_board_t *board)
 	hp_82341_free_private(board);
 }
 
-static const struct pnp_device_id hp_82341_pnp_table[] = {
+static __maybe_unused const struct pnp_device_id hp_82341_pnp_table[] = {
 	{.id = "HWP1411"},
 	{.id = ""}
 };
drivers/staging/gpib/tnt4882/tnt4882_gpib.c +1 -1
index 2e1c3cbebaca..cf3b2a0eb93d 100644
@@ -1390,7 +1390,7 @@ static struct pci_driver tnt4882_pci_driver = {
 	.probe = &tnt4882_pci_probe
 };
 
-static const struct pnp_device_id tnt4882_pnp_table[] = {
+static __maybe_unused const struct pnp_device_id tnt4882_pnp_table[] = {
 	{.id = "NICC601"},
 	{.id = ""}
 };
Signature · 1 line
2.39.5
#1 lore raw
Quoted 46 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

This variable is not referenced in either of these two drivers driver, causing a warning when they are built-in and W=1 warnings are enabled with gcc:

drivers/staging/gpib/tnt4882/tnt4882_gpib.c:1507:35: error: 'tnt4882_pnp_table' defined but not used [-Werror=unused-const-variable=]

 1507 | static const struct pnp_device_id tnt4882_pnp_table[] = {
      |                                   ^~~~~~~~~~~~~~~~~

drivers/staging/gpib/hp_82341/hp_82341.c:811:35: error: 'hp_82341_pnp_table' defined but not used [-Werror=unused-const-variable=]
811 | static const struct pnp_device_id hp_82341_pnp_table[] = {

The MODULE_DEVICE_TABLE() entry does have the effect of loading the module when the PNP device is detected, so it is still needed for the modular case.

Ideally the drivers should be converted to pnp_register_driver(), which would lead to the ID table actually being used.

As a simpler workaround, add a __maybe_unused annotation to shut up the warning.

---
 drivers/staging/gpib/hp_82341/hp_82341.c    | 2 +-
 drivers/staging/gpib/tnt4882/tnt4882_gpib.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/gpib/hp_82341/hp_82341.c +1 -1
index 800f99c05566..7284311e04e2 100644
@@ -808,7 +808,7 @@ static void hp_82341_detach(gpib_board_t *board)
 	hp_82341_free_private(board);
 }
 
-static const struct pnp_device_id hp_82341_pnp_table[] = {
+static __maybe_unused const struct pnp_device_id hp_82341_pnp_table[] = {
 	{.id = "HWP1411"},
 	{.id = ""}
 };
drivers/staging/gpib/tnt4882/tnt4882_gpib.c +0 -0
index 2e1c3cbebaca..cf3b2a0eb93d 100644

drivers/staging/gpib/tnt4882/tnt4882_gpib.c static struct pci_driver tnt4882_pci_driver = { · line 1393

Quoted 5 lines
drivers/staging/gpib/tnt4882/tnt4882_gpib.c +1 -1
@@ -1390,7 +1390,7 @@ static struct pci_driver tnt4882_pci_driver = {
 	.probe = &tnt4882_pci_probe
 };
 
-static const struct pnp_device_id tnt4882_pnp_table[] = {
+static __maybe_unused const struct pnp_device_id tnt4882_pnp_table[] = {

I see this happening in many different drivers right now, what is so unique about pnp that causes this? Shouldn't we fix up the MODULE_DEVICE_TABLE() macro to not require stuff like this instead?

thanks,

greg k-h

#2 lore raw
Quoted 6 lines · Greg Kroah-Hartman
Quoted 5 lines · Arnd Bergmann
drivers/staging/gpib/tnt4882/tnt4882_gpib.c +0 -0
@@ -1390,7 +1390,7 @@ static struct pci_driver tnt4882_pci_driver = {
 	.probe = &tnt4882_pci_probe
 };
 
Quoted 6 lines

drivers/staging/gpib/tnt4882/tnt4882_gpib.c static struct pci_driver tnt4882_pci_driver = { · line 1393

Quoted 2 lines
drivers/staging/gpib/tnt4882/tnt4882_gpib.c +1 -1
-static const struct pnp_device_id tnt4882_pnp_table[] = {
+static __maybe_unused const struct pnp_device_id tnt4882_pnp_table[] = {

I see this happening in many different drivers right now, what is so unique about pnp that causes this? Shouldn't we fix up the MODULE_DEVICE_TABLE() macro to not require stuff like this instead?

I think the other drivers that produce a similar warning usually have a different bug, they have an incorrect of_match_ptr() or ACPI_PTR() around the reference to that table, and the correct fix is usually to just remove those macros. I have previously sent patches for all of these, and could resend those.

These two pnp drivers are special because they predate the linux-2.6 driver model and there is no reference to the table at all in the drivers.

Arnd

#3 lore raw
Quoted 20 lines · Arnd Bergmann
Quoted 6 lines · Greg Kroah-Hartman
Quoted 5 lines · Arnd Bergmann
drivers/staging/gpib/tnt4882/tnt4882_gpib.c +0 -0
@@ -1390,7 +1390,7 @@ static struct pci_driver tnt4882_pci_driver = {
 	.probe = &tnt4882_pci_probe
 };
 
Quoted 6 lines

drivers/staging/gpib/tnt4882/tnt4882_gpib.c static struct pci_driver tnt4882_pci_driver = { · line 1393

Quoted 2 lines
drivers/staging/gpib/tnt4882/tnt4882_gpib.c +1 -1
-static const struct pnp_device_id tnt4882_pnp_table[] = {
+static __maybe_unused const struct pnp_device_id tnt4882_pnp_table[] = {

I see this happening in many different drivers right now, what is so unique about pnp that causes this? Shouldn't we fix up the MODULE_DEVICE_TABLE() macro to not require stuff like this instead?

I think the other drivers that produce a similar warning usually have a different bug, they have an incorrect of_match_ptr() or ACPI_PTR() around the reference to that table, and the correct fix is usually to just remove those macros. I have previously sent patches for all of these, and could resend those.

Quoted 3 lines

These two pnp drivers are special because they predate the linux-2.6 driver model and there is no reference to the table at all in the drivers.

Ah. Then the variable should just be removed as it's obviously not doing anything :)

(I know it's doing module loading, but that's not ok to just fake it this way, it should use that table when it is searching the pnp area.)

So a nice "#if 0" carve out for now perhaps?

thanks,

greg k-h