Commit 01b2bafe authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Rafael J. Wysocki

pnp: Use list_for_each_entry() instead of open coding

Aside from good practice, this avoids a warning from gcc 10:

./include/linux/kernel.h:997:3: warning: array subscript -31 is outside array bounds of ‘struct list_head[1]’ [-Warray-bounds]
  997 |  ((type *)(__mptr - offsetof(type, member))); })
      |  ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./include/linux/list.h:493:2: note: in expansion of macro ‘container_of’
  493 |  container_of(ptr, type, member)
      |  ^~~~~~~~~~~~
./include/linux/pnp.h:275:30: note: in expansion of macro ‘list_entry’
  275 | #define global_to_pnp_dev(n) list_entry(n, struct pnp_dev, global_list)
      |                              ^~~~~~~~~~
./include/linux/pnp.h:281:11: note: in expansion of macro ‘global_to_pnp_dev’
  281 |  (dev) != global_to_pnp_dev(&pnp_global); \
      |           ^~~~~~~~~~~~~~~~~
arch/x86/kernel/rtc.c:189:2: note: in expansion of macro ‘pnp_for_each_dev’
  189 |  pnp_for_each_dev(dev) {

Because the common code doesn't cast the starting list_head to the
containing struct.
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
[ rjw: Whitespace adjustments ]
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent ae83d0b4
...@@ -221,9 +221,7 @@ struct pnp_card { ...@@ -221,9 +221,7 @@ struct pnp_card {
#define protocol_to_pnp_card(n) list_entry(n, struct pnp_card, protocol_list) #define protocol_to_pnp_card(n) list_entry(n, struct pnp_card, protocol_list)
#define to_pnp_card(n) container_of(n, struct pnp_card, dev) #define to_pnp_card(n) container_of(n, struct pnp_card, dev)
#define pnp_for_each_card(card) \ #define pnp_for_each_card(card) \
for((card) = global_to_pnp_card(pnp_cards.next); \ list_for_each_entry(card, &pnp_cards, global_list)
(card) != global_to_pnp_card(&pnp_cards); \
(card) = global_to_pnp_card((card)->global_list.next))
struct pnp_card_link { struct pnp_card_link {
struct pnp_card *card; struct pnp_card *card;
...@@ -276,14 +274,9 @@ struct pnp_dev { ...@@ -276,14 +274,9 @@ struct pnp_dev {
#define card_to_pnp_dev(n) list_entry(n, struct pnp_dev, card_list) #define card_to_pnp_dev(n) list_entry(n, struct pnp_dev, card_list)
#define protocol_to_pnp_dev(n) list_entry(n, struct pnp_dev, protocol_list) #define protocol_to_pnp_dev(n) list_entry(n, struct pnp_dev, protocol_list)
#define to_pnp_dev(n) container_of(n, struct pnp_dev, dev) #define to_pnp_dev(n) container_of(n, struct pnp_dev, dev)
#define pnp_for_each_dev(dev) \ #define pnp_for_each_dev(dev) list_for_each_entry(dev, &pnp_global, global_list)
for((dev) = global_to_pnp_dev(pnp_global.next); \ #define card_for_each_dev(card, dev) \
(dev) != global_to_pnp_dev(&pnp_global); \ list_for_each_entry(dev, &(card)->devices, card_list)
(dev) = global_to_pnp_dev((dev)->global_list.next))
#define card_for_each_dev(card,dev) \
for((dev) = card_to_pnp_dev((card)->devices.next); \
(dev) != card_to_pnp_dev(&(card)->devices); \
(dev) = card_to_pnp_dev((dev)->card_list.next))
#define pnp_dev_name(dev) (dev)->name #define pnp_dev_name(dev) (dev)->name
static inline void *pnp_get_drvdata(struct pnp_dev *pdev) static inline void *pnp_get_drvdata(struct pnp_dev *pdev)
...@@ -437,14 +430,10 @@ struct pnp_protocol { ...@@ -437,14 +430,10 @@ struct pnp_protocol {
}; };
#define to_pnp_protocol(n) list_entry(n, struct pnp_protocol, protocol_list) #define to_pnp_protocol(n) list_entry(n, struct pnp_protocol, protocol_list)
#define protocol_for_each_card(protocol,card) \ #define protocol_for_each_card(protocol, card) \
for((card) = protocol_to_pnp_card((protocol)->cards.next); \ list_for_each_entry(card, &(protocol)->cards, protocol_list)
(card) != protocol_to_pnp_card(&(protocol)->cards); \ #define protocol_for_each_dev(protocol, dev) \
(card) = protocol_to_pnp_card((card)->protocol_list.next)) list_for_each_entry(dev, &(protocol)->devices, protocol_list)
#define protocol_for_each_dev(protocol,dev) \
for((dev) = protocol_to_pnp_dev((protocol)->devices.next); \
(dev) != protocol_to_pnp_dev(&(protocol)->devices); \
(dev) = protocol_to_pnp_dev((dev)->protocol_list.next))
extern struct bus_type pnp_bus_type; extern struct bus_type pnp_bus_type;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment