public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Krzysztof Kozlowski <krzk@kernel.org>
Subject: [PATCH] w1: simplify allocation of w1_master
Date: Mon, 23 Mar 2026 19:15:37 -0700	[thread overview]
Message-ID: <20260324021537.14191-1-rosenp@gmail.com> (raw)

Convert bus_master to a flexible array member as it's being used as one
with the old C89 + 1 pointer trick.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/w1/w1_int.c | 4 +---
 include/linux/w1.h  | 4 ++--
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index 19a0ea28e9f3..a0bb97608564 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -31,12 +31,10 @@ static struct w1_master *w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
 	/*
 	 * We are in process context(kernel thread), so can sleep.
 	 */
-	dev = kzalloc(sizeof(struct w1_master) + sizeof(struct w1_bus_master), GFP_KERNEL);
+	dev = kzalloc_flex(*dev, bus_master, 1);
 	if (!dev)
 		return NULL;

-	dev->bus_master = (struct w1_bus_master *)(dev + 1);
-
 	dev->owner		= THIS_MODULE;
 	dev->max_slave_count	= slave_count;
 	dev->slave_count	= 0;
diff --git a/include/linux/w1.h b/include/linux/w1.h
index 064805bfae3f..7379a9ddefc0 100644
--- a/include/linux/w1.h
+++ b/include/linux/w1.h
@@ -236,9 +236,9 @@ struct w1_master {
 	struct device_driver	*driver;
 	struct device		dev;

-	struct w1_bus_master	*bus_master;
-
 	u32			seq;
+
+	struct w1_bus_master	bus_master[];
 };

 int w1_add_master_device(struct w1_bus_master *master);
--
2.53.0


             reply	other threads:[~2026-03-24  2:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-24  2:15 Rosen Penev [this message]
2026-03-26 10:31 ` [PATCH] w1: simplify allocation of w1_master Krzysztof Kozlowski
2026-03-26 19:08   ` Rosen Penev
2026-03-27  6:42     ` Krzysztof Kozlowski

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=20260324021537.14191-1-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=krzk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox