From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Michael Jamet <michael.jamet@intel.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
Yehezkel Bernat <YehezkelShB@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [resend, PATCH net-next v1 2/2] net: thunderbolt: Use separate header data type for the Rx
Date: Tue, 29 Nov 2022 18:13:59 +0200 [thread overview]
Message-ID: <20221129161359.75792-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20221129161359.75792-1-andriy.shevchenko@linux.intel.com>
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
next prev parent reply other threads:[~2022-11-29 16:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2022-11-30 7:46 ` [resend, PATCH net-next v1 2/2] net: thunderbolt: Use separate header data type for the Rx 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221129161359.75792-2-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=YehezkelShB@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.jamet@intel.com \
--cc=mika.westerberg@linux.intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.