Skip to content

Commit 3ab3112

Browse files
GustavoARSilvagregkh
authored andcommitted
w1: Avoid -Wflex-array-member-not-at-end warnings
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally. Use the `DEFINE_RAW_FLEX()` helper for on-stack definitions of a flexible structure where the size of the flexible-array member is known at compile-time, and refactor the rest of the code, accordingly. So, with these changes, fix the following warnings: drivers/w1/w1_netlink.c:198:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/w1/w1_netlink.c:219:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] Reviewed-by: Kees Cook <kees@kernel.org> Signed-off-by: "Gustavo A. R. Silva" <gustavoars@kernel.org> Link: https://lore.kernel.org/r/Z_RflBe5iDGTMFjV@kspp Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Link: https://lore.kernel.org/r/20250513105326.27385-2-krzysztof.kozlowski@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b808f1c commit 3ab3112

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

drivers/w1/w1_netlink.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,16 @@ static void w1_netlink_queue_status(struct w1_cb_block *block,
194194
static void w1_netlink_send_error(struct cn_msg *cn, struct w1_netlink_msg *msg,
195195
int portid, int error)
196196
{
197-
struct {
198-
struct cn_msg cn;
199-
struct w1_netlink_msg msg;
200-
} packet;
201-
memcpy(&packet.cn, cn, sizeof(packet.cn));
202-
memcpy(&packet.msg, msg, sizeof(packet.msg));
203-
packet.cn.len = sizeof(packet.msg);
204-
packet.msg.len = 0;
205-
packet.msg.status = (u8)-error;
206-
cn_netlink_send(&packet.cn, portid, 0, GFP_KERNEL);
197+
DEFINE_RAW_FLEX(struct cn_msg, packet, data,
198+
sizeof(struct w1_netlink_msg));
199+
struct w1_netlink_msg *pkt_msg = (struct w1_netlink_msg *)packet->data;
200+
201+
*packet = *cn;
202+
*pkt_msg = *msg;
203+
packet->len = sizeof(*pkt_msg);
204+
pkt_msg->len = 0;
205+
pkt_msg->status = (u8)-error;
206+
cn_netlink_send(packet, portid, 0, GFP_KERNEL);
207207
}
208208

209209
/**
@@ -215,22 +215,20 @@ static void w1_netlink_send_error(struct cn_msg *cn, struct w1_netlink_msg *msg,
215215
*/
216216
void w1_netlink_send(struct w1_master *dev, struct w1_netlink_msg *msg)
217217
{
218-
struct {
219-
struct cn_msg cn;
220-
struct w1_netlink_msg msg;
221-
} packet;
222-
memset(&packet, 0, sizeof(packet));
218+
DEFINE_RAW_FLEX(struct cn_msg, packet, data,
219+
sizeof(struct w1_netlink_msg));
220+
struct w1_netlink_msg *pkt_msg = (struct w1_netlink_msg *)packet->data;
223221

224-
packet.cn.id.idx = CN_W1_IDX;
225-
packet.cn.id.val = CN_W1_VAL;
222+
packet->id.idx = CN_W1_IDX;
223+
packet->id.val = CN_W1_VAL;
226224

227-
packet.cn.seq = dev->seq++;
228-
packet.cn.len = sizeof(*msg);
225+
packet->seq = dev->seq++;
226+
packet->len = sizeof(*msg);
229227

230-
memcpy(&packet.msg, msg, sizeof(*msg));
231-
packet.msg.len = 0;
228+
*pkt_msg = *msg;
229+
pkt_msg->len = 0;
232230

233-
cn_netlink_send(&packet.cn, 0, 0, GFP_KERNEL);
231+
cn_netlink_send(packet, 0, 0, GFP_KERNEL);
234232
}
235233

236234
static void w1_send_slave(struct w1_master *dev, u64 rn)

0 commit comments

Comments
 (0)