net: thunderbolt: Switch from __maybe_unused to pm_sleep_ptr() etc
Subsystems (2)
PATCH RESEND 1/2 net: thunderbolt: Switch from __maybe_unused to pm_sleep_ptr() etc
Letting the compiler remove these functions when the kernel is built without CONFIG_PM_SLEEP support is simpler and less heavier for builds than the use of __maybe_unused attributes.
--- drivers/net/thunderbolt.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/thunderbolt.c +4 -6
@@ -1319,7 +1319,7 @@ static void tbnet_shutdown(struct tb_service *svc)tbnet_tear_down (tb_service_get_drvdata (svc), true); } -static int __maybe_unused tbnet_suspend (struct device *dev) +static int tbnet_suspend (struct device *dev) {struct tb_service *svc =tb_to_service (dev);struct tbnet *net =tb_service_get_drvdata (svc);
@@ -1334,7 +1334,7 @@ static int __maybe_unused tbnet_suspend(struct device *dev)return 0 ; } -static int __maybe_unused tbnet_resume (struct device *dev) +static int tbnet_resume (struct device *dev) {struct tb_service *svc =tb_to_service (dev);struct tbnet *net =tb_service_get_drvdata (svc);
@@ -1350,9 +1350,7 @@ static int __maybe_unused tbnet_resume(struct device *dev)return 0 ; } -static const struct dev_pm_ops tbnet_pm_ops = { -SET_SYSTEM_SLEEP_PM_OPS (tbnet_suspend, tbnet_resume) -}; +static DEFINE_SIMPLE_DEV_PM_OPS(tbnet_pm_ops, tbnet_suspend, tbnet_resume);static const struct tb_service_id tbnet_ids[] = { {TB_SERVICE ("network" ,1 ) },
@@ -1364,7 +1362,7 @@ static struct tb_service_driver tbnet_driver = { .driver = { .owner = THIS_MODULE, .name = "thunderbolt-net", - .pm = &tbnet_pm_ops, + .pm = pm_sleep_ptr(&tbnet_pm_ops), }, .probe = tbnet_probe, .remove = tbnet_remove,
Signature · 1 line
2.35.1
PATCH RESEND 2/2 net: thunderbolt: Use separate header data type for the Rx
The same data type structure is used for bitwise operations and regular ones. It makes sparse unhappy, for example:
.../thunderbolt.c:718:23: warning: cast to restricted __le32
.../thunderbolt.c:953:23: warning: incorrect type in initializer (different base types)
.../thunderbolt.c:953:23: expected restricted __wsum [usertype] wsum
.../thunderbolt.c:953:23: got restricted __be32 [usertype]
Split the header to bitwise one and specific for Rx to make sparse happy. Assure the layout by involving static_assert() against size and offsets of the member of the structures.
--- drivers/net/thunderbolt.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/net/thunderbolt.c +21 -1
@@ -58,12 +58,32 @@* supported then @frame_id is filled, otherwise it stays %0. */ struct thunderbolt_ip_frame_header { +__le32 frame_size; +__le16 frame_index; +__le16 frame_id; +__le32 frame_count; +}; + +/* Same as &struct thunderbolt_ip_frame_header for Rx */ +struct thunderbolt_ip_frame_rx_hdr {u32 frame_size;u16 frame_index;u16 frame_id;u32 frame_count; }; +static_assert (sizeof (struct thunderbolt_ip_frame_header ) == +sizeof (struct thunderbolt_ip_frame_rx_hdr )); + +#define TBIP_FRAME_HDR_MATCH (x) \ + static_assert(offsetof(struct thunderbolt_ip_frame_header, frame_##x) == \ + offsetof(struct thunderbolt_ip_frame_rx_hdr, frame_##x)) +TBIP_FRAME_HDR_MATCH (size); +TBIP_FRAME_HDR_MATCH (index); +TBIP_FRAME_HDR_MATCH (id); +TBIP_FRAME_HDR_MATCH (count); +#undef TBIP_FRAME_HDR_MATCH +enum thunderbolt_ip_frame_pdf {TBIP_PDF_FRAME_START =1 ,TBIP_PDF_FRAME_END ,
@@ -193,7 +213,7 @@ struct tbnet {struct delayed_work login_work;struct work_struct connected_work;struct work_struct disconnect_work; -struct thunderbolt_ip_frame_header rx_hdr; +struct thunderbolt_ip_frame_rx_hdr rx_hdr;struct tbnet_ring rx_ring;atomic_t frame_id;struct tbnet_ring tx_ring;
Signature · 1 line
2.35.1
Re: [resend, PATCH net-next v1 2/2] net: thunderbolt: Use separate header data type for the Rx
Quoted 9 lines · Andy Shevchenko
The same data type structure is used for bitwise operations and regular ones. It makes sparse unhappy, for example:
.../thunderbolt.c:718:23: warning: cast to restricted__le32
.../thunderbolt.c:953:23: warning: incorrect type in initializer (different base types)
.../thunderbolt.c:953:23: expected restricted__wsum[usertype] wsum
.../thunderbolt.c:953:23: got restricted__be32[usertype]
Quoted 8 lines
Split the header to bitwise one and specific for Rx to make sparse happy. Assure the layout by involving
static_assert()against size and offsets of the member of the structures.Signed-off-by Andy Shevchenko <[email protected]>--- drivers/net/thunderbolt.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
I would much rather keep the humans reading this happy than add 20+ lines just to silence a tool. Unless this of course is some kind of a real bug.
Re: [resend, PATCH net-next v1 2/2] net: thunderbolt: Use separate header data type for the Rx
Quoted 10 lines · Mika Westerberg
Quoted 9 lines · Andy Shevchenko
The same data type structure is used for bitwise operations and regular ones. It makes sparse unhappy, for example:
.../thunderbolt.c:718:23: warning: cast to restricted__le32
.../thunderbolt.c:953:23: warning: incorrect type in initializer (different base types)
.../thunderbolt.c:953:23: expected restricted__wsum[usertype] wsum
.../thunderbolt.c:953:23: got restricted__be32[usertype]
Quoted 7 lines
Quoted 3 lines
Split the header to bitwise one and specific for Rx to make sparse happy. Assure the layout by involving
static_assert()against size and offsets of the member of the structures.I would much rather keep the humans reading this happy than add 20+ lines just to silence a tool. Unless this of course is some kind of a real bug.
Actually, changing types to bitwise ones reduces the sparse noise (I will double check this) without reducing readability. Would it be accepted?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [resend, PATCH net-next v1 2/2] net: thunderbolt: Use separate header data type for the Rx
Quoted 15 lines · Andy Shevchenko
Quoted 13 lines · Mika Westerberg
Quoted 12 lines · Andy Shevchenko
The same data type structure is used for bitwise operations and regular ones. It makes sparse unhappy, for example:
.../thunderbolt.c:718:23: warning: cast to restricted__le32
.../thunderbolt.c:953:23: warning: incorrect type in initializer (different base types)
.../thunderbolt.c:953:23: expected restricted__wsum[usertype] wsum
.../thunderbolt.c:953:23: got restricted__be32[usertype]Split the header to bitwise one and specific for Rx to make sparse happy. Assure the layout by involving
static_assert()against size and offsets of the member of the structures.
Quoted 7 lines
Quoted 3 lines
I would much rather keep the humans reading this happy than add 20+ lines just to silence a tool. Unless this of course is some kind of a real bug.
Actually, changing types to bitwise ones reduces the sparse noise (I will double check this) without reducing readability. Would it be accepted?
Sure if it makes it more readable and does not add too many lines :)
Re: [resend, PATCH net-next v1 2/2] net: thunderbolt: Use separate header data type for the Rx
Quoted 20 lines · Mika Westerberg
Quoted 19 lines · Andy Shevchenko
Quoted 17 lines · Mika Westerberg
Quoted 5 lines · Andy Shevchenko
The same data type structure is used for bitwise operations and regular ones. It makes sparse unhappy, for example:
.../thunderbolt.c:718:23: warning: cast to restricted__le32Quoted 7 lines
.../thunderbolt.c:953:23: warning: incorrect type in initializer (different base types)
.../thunderbolt.c:953:23: expected restricted__wsum[usertype] wsum
.../thunderbolt.c:953:23: got restricted__be32[usertype]Split the header to bitwise one and specific for Rx to make sparse happy. Assure the layout by involving
static_assert()against size and offsets of the member of the structures.I would much rather keep the humans reading this happy than add 20+ lines just to silence a tool. Unless this of course is some kind of a real bug.
Quoted 5 lines
Quoted 3 lines
Actually, changing types to bitwise ones reduces the sparse noise (I will double check this) without reducing readability. Would it be accepted?
Sure if it makes it more readable and does not add too many lines :)
It replaces types u* by __le*, that's it: -4 +4 LoCs.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
Letting the compiler remove these functions when the kernel is built without
CONFIG_PM_SLEEPsupport is simpler and less heavier for builds than the use of__maybe_unusedattributes.Signed-off-by Andy Shevchenko <[email protected]>