From: Robin Murphy <robin.murphy@arm.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
Will Deacon <will@kernel.org>, Joerg Roedel <joro@8bytes.org>
Cc: iommu@lists.linux-foundation.org,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 1/2] iommu/arm-smmu-v3: Avoid open coded arithmetic in memory allocation
Date: Mon, 7 Feb 2022 10:26:15 +0000 [thread overview]
Message-ID: <f17da9b7-1642-762c-0854-e131e3c2f438@arm.com> (raw)
In-Reply-To: <de9e8705169b5dc873f6ce9f9a17598de89aa6a7.1644081032.git.christophe.jaillet@wanadoo.fr>
On 2022-02-05 17:10, Christophe JAILLET wrote:
> kmalloc_array()/kcalloc() should be used to avoid potential overflow when
> a multiplication is needed to compute the size of the requested memory.
>
> So turn a devm_kzalloc()+explicit size computation into an equivalent
> devm_kcalloc().
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> This is NOT compile tested.
> I don't have the needed cross compiling tools.
FYI, https://cdn.kernel.org/pub/tools/crosstool/
Either way, the patch looks reasonable, thanks!
Acked-by: Robin Murphy <robin.murphy@arm.com>
> ---
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> index 6dc6d8b6b368..14d06aad0726 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -2981,10 +2981,10 @@ static int arm_smmu_init_l1_strtab(struct arm_smmu_device *smmu)
> {
> unsigned int i;
> struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg;
> - size_t size = sizeof(*cfg->l1_desc) * cfg->num_l1_ents;
> void *strtab = smmu->strtab_cfg.strtab;
>
> - cfg->l1_desc = devm_kzalloc(smmu->dev, size, GFP_KERNEL);
> + cfg->l1_desc = devm_kcalloc(smmu->dev, cfg->num_l1_ents,
> + sizeof(*cfg->l1_desc), GFP_KERNEL);
> if (!cfg->l1_desc)
> return -ENOMEM;
>
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
prev parent reply other threads:[~2022-02-07 10:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-05 17:10 [PATCH 1/2] iommu/arm-smmu-v3: Avoid open coded arithmetic in memory allocation Christophe JAILLET
2022-02-05 17:11 ` [PATCH 2/2] iommu/arm-smmu-v3: Simplify " Christophe JAILLET
2022-02-07 10:56 ` Robin Murphy
2022-02-07 10:26 ` Robin Murphy [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=f17da9b7-1642-762c-0854-e131e3c2f438@arm.com \
--to=robin.murphy@arm.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=iommu@lists.linux-foundation.org \
--cc=joro@8bytes.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=will@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