From: Takashi Iwai <tiwai@suse.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: alsa-devel@alsa-project.org
Subject: Re: [bug report] ALSA: memalloc: Add fallback SG-buffer allocations for x86
Date: Wed, 20 Apr 2022 10:00:47 +0200 [thread overview]
Message-ID: <s5htuaoxjyo.wl-tiwai@suse.de> (raw)
In-Reply-To: <20220420074458.GA32681@kili>
On Wed, 20 Apr 2022 09:44:58 +0200,
Dan Carpenter wrote:
>
> Hello Takashi Iwai,
>
> The patch 925ca893b4a6: "ALSA: memalloc: Add fallback SG-buffer
> allocations for x86" from Apr 13, 2022, leads to the following Smatch
> static checker warning:
>
> sound/core/memalloc.c:732 snd_dma_sg_fallback_alloc()
> error: 'p' came from dma_alloc_coherent() so we can't do virt_to_phys()
>
> sound/core/memalloc.c
> 708 static void *snd_dma_sg_fallback_alloc(struct snd_dma_buffer *dmab, size_t size)
> 709 {
> 710 struct snd_dma_sg_fallback *sgbuf;
> 711 struct page **pages;
> 712 size_t i, count;
> 713 void *p;
> 714
> 715 sgbuf = kzalloc(sizeof(*sgbuf), GFP_KERNEL);
> 716 if (!sgbuf)
> 717 return NULL;
> 718 count = PAGE_ALIGN(size) >> PAGE_SHIFT;
> 719 pages = kvcalloc(count, sizeof(*pages), GFP_KERNEL);
> 720 if (!pages)
> 721 goto error;
> 722 sgbuf->pages = pages;
> 723 sgbuf->addrs = kvcalloc(count, sizeof(*sgbuf->addrs), GFP_KERNEL);
> 724 if (!sgbuf->addrs)
> 725 goto error;
> 726
> 727 for (i = 0; i < count; sgbuf->count++, i++) {
> 728 p = dma_alloc_coherent(dmab->dev.dev, PAGE_SIZE,
> 729 &sgbuf->addrs[i], DEFAULT_GFP);
> 730 if (!p)
> 731 goto error;
> --> 732 sgbuf->pages[i] = virt_to_page(p);
>
> The warning is a bit useless. It's complaining about __phys_addr()
> and not virt_to_phys(). I don't really understand the rules here, it
> might be legal in certain contexts.
In general it's not good to perform virt_to_page() for the
dma_alloc_coherent(), but here the code is special only for x86 and
certain circumstances, so this must work -- it's the very same stuff
we had over a decade, after all. The code was resurrected in a
simplified form as a fallback now.
thanks,
Takashi
prev parent reply other threads:[~2022-04-20 8:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-20 7:44 [bug report] ALSA: memalloc: Add fallback SG-buffer allocations for x86 Dan Carpenter
2022-04-20 8:00 ` Takashi Iwai [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=s5htuaoxjyo.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--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.