From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Rosen Penev <rosenp@gmail.com>
Cc: linux-usb@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
open list <linux-kernel@vger.kernel.org>,
"open list:KERNEL HARDENING (not covered by other
areas):Keyword:b__counted_by(_le|_be)?b"
<linux-hardening@vger.kernel.org>
Subject: Re: [PATCH] usb: typec: intel_pmc_mux: combine kzalloc + kcalloc
Date: Wed, 15 Apr 2026 15:56:59 +0300 [thread overview]
Message-ID: <ad-LG9g4GI3uuhrE@kuha> (raw)
In-Reply-To: <20260411023642.146890-1-rosenp@gmail.com>
Hi Rosen,
On Fri, Apr 10, 2026 at 07:36:42PM -0700, Rosen Penev wrote:
> A flexible array member can be used to combine allocations and simplify
> handling slightly.
>
> Add __counted_by for extra runtime analysis.
One nitpick below.
Otherwise this looks okay to me.
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> drivers/usb/typec/mux/intel_pmc_mux.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/usb/typec/mux/intel_pmc_mux.c b/drivers/usb/typec/mux/intel_pmc_mux.c
> index 1698428654ab..8b0a3dd3f940 100644
> --- a/drivers/usb/typec/mux/intel_pmc_mux.c
> +++ b/drivers/usb/typec/mux/intel_pmc_mux.c
> @@ -151,13 +151,14 @@ struct pmc_usb {
> u8 num_ports;
> struct device *dev;
> struct intel_scu_ipc_dev *ipc;
> - struct pmc_usb_port *port;
> struct acpi_device *iom_adev;
> void __iomem *iom_base;
> u32 iom_port_status_offset;
> u8 iom_port_status_size;
>
> struct dentry *dentry;
> +
> + struct pmc_usb_port port[] __counted_by(num_ports);
> };
>
> static struct dentry *pmc_mux_debugfs_root;
> @@ -731,27 +732,26 @@ static int pmc_usb_probe(struct platform_device *pdev)
> {
> struct fwnode_handle *fwnode = NULL;
> struct pmc_usb *pmc;
> + u8 num_ports;
> int i = 0;
> int ret;
>
> - pmc = devm_kzalloc(&pdev->dev, sizeof(*pmc), GFP_KERNEL);
> - if (!pmc)
> - return -ENOMEM;
> -
> device_for_each_child_node(&pdev->dev, fwnode)
> - pmc->num_ports++;
> + num_ports++;
>
> /* The IOM microcontroller has a limitation of max 4 ports. */
> - if (pmc->num_ports > 4) {
> + if (num_ports > 4) {
> dev_err(&pdev->dev, "driver limited to 4 ports\n");
> return -ERANGE;
> }
>
> - pmc->port = devm_kcalloc(&pdev->dev, pmc->num_ports,
> - sizeof(struct pmc_usb_port), GFP_KERNEL);
> - if (!pmc->port)
> + pmc = devm_kzalloc(&pdev->dev, struct_size(pmc, port, num_ports),
> + GFP_KERNEL);
One line is enough for that.
> + if (!pmc)
> return -ENOMEM;
>
> + pmc->num_ports = num_ports;
> +
> pmc->ipc = devm_intel_scu_ipc_dev_get(&pdev->dev);
> if (!pmc->ipc)
> return -EPROBE_DEFER;
> --
> 2.53.0
thanks,
--
heikki
prev parent reply other threads:[~2026-04-15 12:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-11 2:36 [PATCH] usb: typec: intel_pmc_mux: combine kzalloc + kcalloc Rosen Penev
2026-04-13 8:51 ` kernel test robot
2026-04-13 19:47 ` Rosen Penev
2026-04-15 12:56 ` Heikki Krogerus [this message]
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=ad-LG9g4GI3uuhrE@kuha \
--to=heikki.krogerus@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=rosenp@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox