From: Dan Carpenter <dan.carpenter@oracle.com>
To: hch@lst.de
Cc: xen-devel@lists.xenproject.org,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org
Subject: [bug report] x86/xen: open code alloc_vm_area in arch_gnttab_valloc
Date: Thu, 24 Sep 2020 11:50:44 +0300 [thread overview]
Message-ID: <20200924085044.GA1569000@mwanda> (raw)
Hello Christoph Hellwig,
The patch a0e7ac6b4907: "x86/xen: open code alloc_vm_area in
arch_gnttab_valloc" from Sep 23, 2020, leads to the following static
checker warning:
arch/x86/xen/grant-table.c:110 arch_gnttab_valloc()
warn: did you mean to pass the address of 'area->ptes'
arch/x86/xen/grant-table.c
93 static int gnttab_apply(pte_t *pte, unsigned long addr, void *data)
94 {
95 pte_t ***p = data;
96
97 **p = pte;
98 (*p)++;
99 return 0;
100 }
101
102 static int arch_gnttab_valloc(struct gnttab_vm_area *area, unsigned nr_frames)
103 {
104 area->ptes = kmalloc_array(nr_frames, sizeof(*area->ptes), GFP_KERNEL);
area->ptes is allocated here.
105 if (area->ptes == NULL)
106 return -ENOMEM;
107 area->area = get_vm_area(PAGE_SIZE * nr_frames, VM_IOREMAP);
108 if (!area->area)
109 goto out_free_ptes;
110 if (apply_to_page_range(&init_mm, (unsigned long)area->area->addr,
111 PAGE_SIZE * nr_frames, gnttab_apply, &area->ptes))
^^^^^^^^^^^
This increments area->ptes. In the original code, there was a stack
variable which was changed and the area->ptes pointer wasn't modified.
112 goto out_free_vm_area;
113 return 0;
114 out_free_vm_area:
115 free_vm_area(area->area);
116 out_free_ptes:
117 kfree(area->ptes);
^^^^^^^^^^^^^^^^^
This frees a different pointer from what was allocated.
118 return -ENOMEM;
119 }
regards,
dan carpenter
next reply other threads:[~2020-09-24 8:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-24 8:50 Dan Carpenter [this message]
2020-09-24 10:10 ` [bug report] x86/xen: open code alloc_vm_area in arch_gnttab_valloc Christoph Hellwig
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=20200924085044.GA1569000@mwanda \
--to=dan.carpenter@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=hch@lst.de \
--cc=linux-mm@kvack.org \
--cc=xen-devel@lists.xenproject.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).