From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Simon Horman <horms@kernel.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
netdev@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Subject: Re: [PATCH net-next v3 2/3] net: airoha: npu: Add airoha_npu_soc_data struct
Date: Tue, 14 Oct 2025 15:52:40 +0200 [thread overview]
Message-ID: <aO5VqDegyOY9fVEK@lore-desk> (raw)
In-Reply-To: <20251014134609.GA3239414@horms.kernel.org>
[-- Attachment #1: Type: text/plain, Size: 4546 bytes --]
On Oct 14, Simon Horman wrote:
> On Tue, Oct 14, 2025 at 11:23:37AM +0200, Lorenzo Bianconi wrote:
> > > On Mon, Oct 13, 2025 at 03:58:50PM +0200, Lorenzo Bianconi wrote:
> > >
> > > ...
> > >
> > > > @@ -182,49 +192,53 @@ static int airoha_npu_send_msg(struct airoha_npu *npu, int func_id,
> > > > return ret;
> > > > }
> > > >
> > > > -static int airoha_npu_run_firmware(struct device *dev, void __iomem *base,
> > > > - struct resource *res)
> > > > +static int airoha_npu_load_firmware(struct device *dev, void __iomem *addr,
> > > > + const struct airoha_npu_fw *fw_info)
> > > > {
> > > > const struct firmware *fw;
> > > > - void __iomem *addr;
> > > > int ret;
> > > >
> > > > - ret = request_firmware(&fw, NPU_EN7581_FIRMWARE_RV32, dev);
> > > > + ret = request_firmware(&fw, fw_info->name, dev);
> > > > if (ret)
> > > > return ret == -ENOENT ? -EPROBE_DEFER : ret;
> > > >
> > > > - if (fw->size > NPU_EN7581_FIRMWARE_RV32_MAX_SIZE) {
> > > > + if (fw->size > fw_info->max_size) {
> > > > dev_err(dev, "%s: fw size too overlimit (%zu)\n",
> > > > - NPU_EN7581_FIRMWARE_RV32, fw->size);
> > > > + fw_info->name, fw->size);
> > > > ret = -E2BIG;
> > > > goto out;
> > > > }
> > > >
> > > > - addr = devm_ioremap_resource(dev, res);
> > > > - if (IS_ERR(addr)) {
> > > > - ret = PTR_ERR(addr);
> > > > - goto out;
> > > > - }
> > > > -
> > > > memcpy_toio(addr, fw->data, fw->size);
> > > > +out:
> > > > release_firmware(fw);
> > > >
> > > > - ret = request_firmware(&fw, NPU_EN7581_FIRMWARE_DATA, dev);
> > > > - if (ret)
> > > > - return ret == -ENOENT ? -EPROBE_DEFER : ret;
> > > > + return ret;
> > > > +}
> > > >
> > > > - if (fw->size > NPU_EN7581_FIRMWARE_DATA_MAX_SIZE) {
> > > > - dev_err(dev, "%s: fw size too overlimit (%zu)\n",
> > > > - NPU_EN7581_FIRMWARE_DATA, fw->size);
> > > > - ret = -E2BIG;
> > > > - goto out;
> > > > - }
> > > > +static int airoha_npu_run_firmware(struct device *dev, void __iomem *base,
> > > > + struct resource *res)
> > > > +{
> > > > + const struct airoha_npu_soc_data *soc;
> > > > + void __iomem *addr;
> > > > + int ret;
> > > >
> > > > - memcpy_toio(base + REG_NPU_LOCAL_SRAM, fw->data, fw->size);
> > > > -out:
> > > > - release_firmware(fw);
> > > > + soc = of_device_get_match_data(dev);
> > > > + if (!soc)
> > > > + return -EINVAL;
> > > >
> > > > - return ret;
> > > > + addr = devm_ioremap_resource(dev, res);
> > > > + if (IS_ERR(addr))
> > > > + return PTR_ERR(addr);
> > > > +
> > > > + /* Load rv32 npu firmware */
> > > > + ret = airoha_npu_load_firmware(dev, addr, &soc->fw_rv32);
> > > > + if (ret)
> > > > + return ret;
> > > > +
> > > > + /* Load data npu firmware */
> > > > + return airoha_npu_load_firmware(dev, base + REG_NPU_LOCAL_SRAM,
> > > > + &soc->fw_data);
> > >
> > > Hi Lorenzo,
> >
> > Hi Simon,
> >
> > >
> > > There are two calls to airoha_npu_load_firmware() above.
> > > And, internally, airoha_npu_load_firmware() will call release_firmware()
> > > if an error is encountered.
> > >
> > > But should release_firmware() be called for the firmware requested
> > > by the first call to airoha_npu_load_firmware() if the second call fails?
> > > Such clean-up seems to have been the case prior to this patch.
> >
> > release_firmware() is intended to release the resources allocated by the
> > corresponding call to request_firmware() in airoha_npu_load_firmware().
> > According to my understanding we always run release_firmware() in
> > airoha_npu_load_firmware() before returning to the caller. Even before this
> > patch we run release_firmware() on the 'first' firmware image before requesting
> > the second one. Am I missing something?
> >
> > >
> > > Also, not strictly related. Should release_firmware() be called (twice)
> > > when the driver is removed?
> >
> > For the above reasons, it is not important to call release_firmware() removing
> > the module. Agree?
>
> Thanks, agreed.
>
> For some reason I missed that release_firmware() is called in
> airoha_npu_load_firmware() regardless of error - I thought it was only
> in error paths for some reason.
>
> So I agree that the firmware is always released by the time
> airoha_npu_load_firmware() is returned. As thus there is never
> a need to release it afterwards.
>
> Reviewed-by: Simon Horman <horms@kernel.org>
>
>
ack, thx for the review.
Regards,
Lorenzo
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2025-10-14 13:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-13 13:58 [PATCH net-next v3 0/3] net: airoha: npu: Introduce support for Airoha 7583 NPU Lorenzo Bianconi
2025-10-13 13:58 ` [PATCH net-next v3 1/3] dt-bindings: net: airoha: npu: Add AN7583 support Lorenzo Bianconi
2025-10-13 13:58 ` [PATCH net-next v3 2/3] net: airoha: npu: Add airoha_npu_soc_data struct Lorenzo Bianconi
2025-10-14 8:34 ` Simon Horman
2025-10-14 9:23 ` Lorenzo Bianconi
2025-10-14 13:46 ` Simon Horman
2025-10-14 13:52 ` Lorenzo Bianconi [this message]
2025-10-13 13:58 ` [PATCH net-next v3 3/3] net: airoha: npu: Add 7583 SoC support Lorenzo Bianconi
2025-10-14 8:35 ` Simon Horman
2025-10-16 1:00 ` [PATCH net-next v3 0/3] net: airoha: npu: Introduce support for Airoha 7583 NPU patchwork-bot+netdevbpf
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=aO5VqDegyOY9fVEK@lore-desk \
--to=lorenzo@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=robh@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;
as well as URLs for NNTP newsgroup(s).