All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: netdev@vger.kernel.org
Cc: Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Richard Cochran <richardcochran@gmail.com>,
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH net-next] net: phy: microchip_rds_ptp: simplify allocation
Date: Sun, 15 Mar 2026 14:45:27 -0700	[thread overview]
Message-ID: <20260315214527.4113-1-rosenp@gmail.com> (raw)

Simplifies allocations by using a flexible array member in this struct.

Remove memset as it's now allocated by kzalloc.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/net/phy/microchip_rds_ptp.c | 10 ++--------
 drivers/net/phy/microchip_rds_ptp.h |  2 +-
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/net/phy/microchip_rds_ptp.c b/drivers/net/phy/microchip_rds_ptp.c
index 2ad95d5c9d86..4e6ed11f9334 100644
--- a/drivers/net/phy/microchip_rds_ptp.c
+++ b/drivers/net/phy/microchip_rds_ptp.c
@@ -1246,7 +1246,8 @@ struct mchp_rds_ptp_clock *mchp_rds_ptp_probe(struct phy_device *phydev, u8 mmd,
 	struct mchp_rds_ptp_clock *clock;
 	int rc;

-	clock = devm_kzalloc(&phydev->mdio.dev, sizeof(*clock), GFP_KERNEL);
+	clock = devm_kzalloc(&phydev->mdio.dev,
+			struct_size(clock, pin_config, MCHP_RDS_PTP_N_PIN), GFP_KERNEL);
 	if (!clock)
 		return ERR_PTR(-ENOMEM);

@@ -1255,17 +1256,10 @@ struct mchp_rds_ptp_clock *mchp_rds_ptp_probe(struct phy_device *phydev, u8 mmd,
 	clock->mmd		= mmd;

 	mutex_init(&clock->ptp_lock);
-	clock->pin_config = devm_kmalloc_array(&phydev->mdio.dev,
-					       MCHP_RDS_PTP_N_PIN,
-					       sizeof(*clock->pin_config),
-					       GFP_KERNEL);
-	if (!clock->pin_config)
-		return ERR_PTR(-ENOMEM);

 	for (int i = 0; i < MCHP_RDS_PTP_N_PIN; ++i) {
 		struct ptp_pin_desc *p = &clock->pin_config[i];

-		memset(p, 0, sizeof(*p));
 		snprintf(p->name, sizeof(p->name), "pin%d", i);
 		p->index = i;
 		p->func = PTP_PF_NONE;
diff --git a/drivers/net/phy/microchip_rds_ptp.h b/drivers/net/phy/microchip_rds_ptp.h
index 25af68337b94..f5c6ab585fff 100644
--- a/drivers/net/phy/microchip_rds_ptp.h
+++ b/drivers/net/phy/microchip_rds_ptp.h
@@ -199,7 +199,7 @@ struct mchp_rds_ptp_clock {
 	u8 mmd;
 	int mchp_rds_ptp_event;
 	int event_pin;
-	struct ptp_pin_desc *pin_config;
+	struct ptp_pin_desc pin_config[];
 };

 struct mchp_rds_ptp_rx_ts {
--
2.53.0


             reply	other threads:[~2026-03-15 21:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-15 21:45 Rosen Penev [this message]
2026-03-19  1:29 ` [PATCH net-next] net: phy: microchip_rds_ptp: simplify allocation Jakub Kicinski

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=20260315214527.4113-1-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.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.