* [resend, PATCH net-next v1 1/2] net: thunderbolt: Switch from __maybe_unused to pm_sleep_ptr() etc
@ 2022-11-29 16:13 Andy Shevchenko
2022-11-29 16:13 ` [resend, PATCH net-next v1 2/2] net: thunderbolt: Use separate header data type for the Rx Andy Shevchenko
2022-11-30 7:43 ` [resend, PATCH net-next v1 1/2] net: thunderbolt: Switch from __maybe_unused to pm_sleep_ptr() etc Mika Westerberg
0 siblings, 2 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-11-29 16:13 UTC (permalink / raw)
To: netdev, linux-kernel
Cc: Michael Jamet, Mika Westerberg, Yehezkel Bernat, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Andy Shevchenko
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.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/net/thunderbolt.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/net/thunderbolt.c b/drivers/net/thunderbolt.c
index a52ee2bf5575..4dbc6c7f2e10 100644
--- a/drivers/net/thunderbolt.c
+++ b/drivers/net/thunderbolt.c
@@ -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,
--
2.35.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [resend, PATCH net-next v1 2/2] net: thunderbolt: Use separate header data type for the Rx
2022-11-29 16:13 [resend, PATCH net-next v1 1/2] net: thunderbolt: Switch from __maybe_unused to pm_sleep_ptr() etc Andy Shevchenko
@ 2022-11-29 16:13 ` Andy Shevchenko
2022-11-30 7:46 ` Mika Westerberg
2022-11-30 7:43 ` [resend, PATCH net-next v1 1/2] net: thunderbolt: Switch from __maybe_unused to pm_sleep_ptr() etc Mika Westerberg
1 sibling, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2022-11-29 16:13 UTC (permalink / raw)
To: netdev, linux-kernel
Cc: Michael Jamet, Mika Westerberg, Yehezkel Bernat, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, 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.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/net/thunderbolt.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/drivers/net/thunderbolt.c b/drivers/net/thunderbolt.c
index 4dbc6c7f2e10..f7b3d0d4646c 100644
--- a/drivers/net/thunderbolt.c
+++ b/drivers/net/thunderbolt.c
@@ -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;
--
2.35.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [resend, PATCH net-next v1 1/2] net: thunderbolt: Switch from __maybe_unused to pm_sleep_ptr() etc
2022-11-29 16:13 [resend, PATCH net-next v1 1/2] net: thunderbolt: Switch from __maybe_unused to pm_sleep_ptr() etc Andy Shevchenko
2022-11-29 16:13 ` [resend, PATCH net-next v1 2/2] net: thunderbolt: Use separate header data type for the Rx Andy Shevchenko
@ 2022-11-30 7:43 ` Mika Westerberg
1 sibling, 0 replies; 7+ messages in thread
From: Mika Westerberg @ 2022-11-30 7:43 UTC (permalink / raw)
To: Andy Shevchenko
Cc: netdev, linux-kernel, Michael Jamet, Yehezkel Bernat,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
On Tue, Nov 29, 2022 at 06:13:58PM +0200, Andy Shevchenko wrote:
> 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.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [resend, PATCH net-next v1 2/2] net: thunderbolt: Use separate header data type for the Rx
2022-11-29 16:13 ` [resend, PATCH net-next v1 2/2] net: thunderbolt: Use separate header data type for the Rx Andy Shevchenko
@ 2022-11-30 7:46 ` Mika Westerberg
2022-11-30 10:51 ` Andy Shevchenko
0 siblings, 1 reply; 7+ messages in thread
From: Mika Westerberg @ 2022-11-30 7:46 UTC (permalink / raw)
To: Andy Shevchenko
Cc: netdev, linux-kernel, Michael Jamet, Yehezkel Bernat,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
On Tue, Nov 29, 2022 at 06:13:59PM +0200, Andy Shevchenko wrote:
> 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.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> 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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [resend, PATCH net-next v1 2/2] net: thunderbolt: Use separate header data type for the Rx
2022-11-30 7:46 ` Mika Westerberg
@ 2022-11-30 10:51 ` Andy Shevchenko
2022-11-30 11:09 ` Mika Westerberg
0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2022-11-30 10:51 UTC (permalink / raw)
To: Mika Westerberg
Cc: netdev, linux-kernel, Michael Jamet, Yehezkel Bernat,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
On Wed, Nov 30, 2022 at 09:46:16AM +0200, Mika Westerberg wrote:
> On Tue, Nov 29, 2022 at 06:13:59PM +0200, Andy Shevchenko wrote:
> > 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.
> 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?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [resend, PATCH net-next v1 2/2] net: thunderbolt: Use separate header data type for the Rx
2022-11-30 10:51 ` Andy Shevchenko
@ 2022-11-30 11:09 ` Mika Westerberg
2022-11-30 11:38 ` Andy Shevchenko
0 siblings, 1 reply; 7+ messages in thread
From: Mika Westerberg @ 2022-11-30 11:09 UTC (permalink / raw)
To: Andy Shevchenko
Cc: netdev, linux-kernel, Michael Jamet, Yehezkel Bernat,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
On Wed, Nov 30, 2022 at 12:51:06PM +0200, Andy Shevchenko wrote:
> On Wed, Nov 30, 2022 at 09:46:16AM +0200, Mika Westerberg wrote:
> > On Tue, Nov 29, 2022 at 06:13:59PM +0200, Andy Shevchenko wrote:
> > > 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.
>
> > 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 :)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [resend, PATCH net-next v1 2/2] net: thunderbolt: Use separate header data type for the Rx
2022-11-30 11:09 ` Mika Westerberg
@ 2022-11-30 11:38 ` Andy Shevchenko
0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-11-30 11:38 UTC (permalink / raw)
To: Mika Westerberg
Cc: netdev, linux-kernel, Michael Jamet, Yehezkel Bernat,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
On Wed, Nov 30, 2022 at 01:09:59PM +0200, Mika Westerberg wrote:
> On Wed, Nov 30, 2022 at 12:51:06PM +0200, Andy Shevchenko wrote:
> > On Wed, Nov 30, 2022 at 09:46:16AM +0200, Mika Westerberg wrote:
> > > On Tue, Nov 29, 2022 at 06:13:59PM +0200, Andy Shevchenko wrote:
> > > > 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.
> >
> > > 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 :)
It replaces types u* by __le*, that's it: -4 +4 LoCs.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-11-30 11:38 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-29 16:13 [resend, PATCH net-next v1 1/2] net: thunderbolt: Switch from __maybe_unused to pm_sleep_ptr() etc Andy Shevchenko
2022-11-29 16:13 ` [resend, PATCH net-next v1 2/2] net: thunderbolt: Use separate header data type for the Rx Andy Shevchenko
2022-11-30 7:46 ` Mika Westerberg
2022-11-30 10:51 ` Andy Shevchenko
2022-11-30 11:09 ` Mika Westerberg
2022-11-30 11:38 ` Andy Shevchenko
2022-11-30 7:43 ` [resend, PATCH net-next v1 1/2] net: thunderbolt: Switch from __maybe_unused to pm_sleep_ptr() etc Mika Westerberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).