All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rojewski, Cezary" <cezary.rojewski@intel.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: "alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>
Subject: RE: [bug report] ASoC: Intel: catpt: Firmware loading and context restore
Date: Mon, 12 Oct 2020 08:48:15 +0000	[thread overview]
Message-ID: <423749645740488bab10cb3565426279@intel.com> (raw)
In-Reply-To: <20201010201547.GA1890676@mwanda>

On 2020-10-10 10:15 PM, Dan Carpenter wrote:
> Hello Cezary Rojewski,
> 
> The patch a9aa6fb3eb6c: "ASoC: Intel: catpt: Firmware loading and
> context restore" from Sep 29, 2020, leads to the following static
> checker warning:
> 
> 	sound/soc/intel/catpt/loader.c:654 catpt_first_boot_firmware()
> 	warn: consider using resource_size() here
> 
> sound/soc/intel/catpt/loader.c
>     638  int catpt_first_boot_firmware(struct catpt_dev *cdev)
>     639  {
>     640          struct resource *res;
>     641          int ret;
>     642
>     643          ret = catpt_boot_firmware(cdev, false);
>     644          if (ret) {
>     645                  dev_err(cdev->dev, "basefw boot failed: %d\n", ret);
>     646                  return ret;
>     647          }
>     648
>     649          /* restrict FW Core dump area */
>     650          __request_region(&cdev->dram, 0, 0x200, NULL, 0);
>     651          /* restrict entire area following BASE_FW - highest offset in DRAM */
>     652          for (res = cdev->dram.child; res->sibling; res = res->sibling)
>     653                  ;
>     654          __request_region(&cdev->dram, res->end + 1,
>     655                           cdev->dram.end - res->end, NULL, 0);
>                                   ^^^^^^^^^^^^^^^^^^^^^^^^^
> It's been years since I have seen one of these warnings.  Back in the
> day we used have have a lot of off by one warnings because resource_size()
> is supposed to be calculated as "end - start + 1".  But here we are
> calculating "dram.end - res->end" so I'm not sure if the math is correct
> or not.  This is very new code so hopefully you know the answer off the
> top of your head?
> 
> 

Hello Dan,

Thanks for your report. However, I do not see any problem with above
code.

Let me elaborate the context so both parties are aware of what's going
on:
Host (kernel driver) is tasked with reserving entire region of DRAM past
the module (aka resource) with highest offset. Offset is unknown
upfront. It needs to be searched for. So, after all modules have their
adequate DRAM space assigned, we search for the very last module. Its
'end + 1' marks the beginning of DSP-reserved region, that is one that
DSP firmware will be making use of internally. Host needs to reserve it
early so further reservations (done e.g.: on audio stream open) won't
target said region. 'dram.end' on the other hand marks the end of the
entire block - past that point IRAM begins. Area in-between is what we
need to flag as already in-use.

Some basic math/example:
	dram.start = 0x0
	dram.end = 0xAFFFF
	resource_size(dram) = 0xAFFFF - 0x0 + 1 = 0xB0000

found 'res':
	res.end = 0x9FFFF

area to be reserved:
	target.start = res.end + 1 = 0xA0000
	target.end = dram.end = 0xAFFFF
	resource_size(target) = 0xAFFFF - 0xA0000 + 1 = 0x10000

and so:
	dram.end - res.end = 0xAFFFF - 0x9FFFF = 0x10000
what equals resource_size(target).

Please, let me know if I'm missing something here.

Thanks,
Czarek


      reply	other threads:[~2020-10-12  8:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-10 20:15 [bug report] ASoC: Intel: catpt: Firmware loading and context restore Dan Carpenter
2020-10-12  8:48 ` Rojewski, Cezary [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=423749645740488bab10cb3565426279@intel.com \
    --to=cezary.rojewski@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=dan.carpenter@oracle.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.