From: Andrew Morton <akpm@linux-foundation.org>
To: Alexey Khoroshilov <khoroshilov@ispras.ru>,
Alexandre Bounine <alexandre.bounine@idt.com>,
Matt Porter <mporter@kernel.crashing.org>,
linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org
Subject: Re: [PATCH] rapidio: avoid GFP_KERNEL in atomic context in riocm_send_close()
Date: Sat, 10 Sep 2016 21:44:38 -0700 [thread overview]
Message-ID: <20160910214438.de89220445c47eb0d69c9f77@linux-foundation.org> (raw)
In-Reply-To: <20160909212214.d520462c3c64c681a05a06b1@linux-foundation.org>
On Fri, 9 Sep 2016 21:22:14 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
> Why not just make `hdr' a local? It isn't very large and the code
> becomes smaller and faster.
Actually, doing it this way saves some code size and is faster:
From: Andrew Morton <akpm@linux-foundation.org>
Subject: drivers/rapidio/rio_cm.c: avoid GFP_KERNEL in atomic context
riocm_send_close() is called from rio_cm_shutdown() under
spin_lock_bh(idr_lock), but riocm_send_close() uses a GFP_KERNEL
allocation.
Fix this by making local `hdr' a local variable rather than obtaining it
via kmalloc().
Found by Linux Driver Verification project (linuxtesting.org).
Link: http://lkml.kernel.org/r/1473453815-15914-1-git-send-email-khoroshilov@ispras.ru
Reported-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Cc: Alexandre Bounine <alexandre.bounine@idt.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
drivers/rapidio/rio_cm.c | 38 ++++++++++++++++---------------------
1 file changed, 17 insertions(+), 21 deletions(-)
diff -puN drivers/rapidio/rio_cm.c~drivers-rapidio-rio_cmc-avoid-gfp_kernel-in-atomic-context drivers/rapidio/rio_cm.c
--- a/drivers/rapidio/rio_cm.c~drivers-rapidio-rio_cmc-avoid-gfp_kernel-in-atomic-context
+++ a/drivers/rapidio/rio_cm.c
@@ -1395,38 +1395,34 @@ static void riocm_ch_free(struct kref *r
complete(&ch->comp_close);
}
+/*
+ * Send CH_CLOSE notification to the remote RapidIO device
+ */
static int riocm_send_close(struct rio_channel *ch)
{
- struct rio_ch_chan_hdr *hdr;
int ret;
-
- /*
- * Send CH_CLOSE notification to the remote RapidIO device
- */
-
- hdr = kzalloc(sizeof(*hdr), GFP_KERNEL);
- if (hdr == NULL)
- return -ENOMEM;
-
- hdr->bhdr.src_id = htonl(ch->loc_destid);
- hdr->bhdr.dst_id = htonl(ch->rem_destid);
- hdr->bhdr.src_mbox = cmbox;
- hdr->bhdr.dst_mbox = cmbox;
- hdr->bhdr.type = RIO_CM_CHAN;
- hdr->ch_op = CM_CONN_CLOSE;
- hdr->dst_ch = htons(ch->rem_channel);
- hdr->src_ch = htons(ch->id);
+ struct rio_ch_chan_hdr hdr = {
+ .bhdr = {
+ .src_id = htonl(ch->loc_destid),
+ .dst_id = htonl(ch->rem_destid),
+ .src_mbox = cmbox,
+ .dst_mbox = cmbox,
+ .type = RIO_CM_CHAN,
+ },
+ .ch_op = CM_CONN_CLOSE,
+ .dst_ch = htons(ch->rem_channel),
+ .src_ch = htons(ch->id),
+ };
/* ATTN: the function call below relies on the fact that underlying
* add_outb_message() routine copies TX data into its internal transfer
* buffer. Needs to be reviewed if switched to direct buffer mode.
*/
- ret = riocm_post_send(ch->cmdev, ch->rdev, hdr, sizeof(*hdr));
+ ret = riocm_post_send(ch->cmdev, ch->rdev, &hdr, sizeof(hdr));
if (ret == -EBUSY && !riocm_queue_req(ch->cmdev, ch->rdev,
- hdr, sizeof(*hdr)))
+ &hdr, sizeof(hdr)))
return 0;
- kfree(hdr);
if (ret)
riocm_error("ch(%d) send CLOSE failed (ret=%d)", ch->id, ret);
_
next prev parent reply other threads:[~2016-09-11 4:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-09 20:43 Alexey Khoroshilov
2016-09-10 4:22 ` Andrew Morton
2016-09-11 4:44 ` Andrew Morton [this message]
2016-09-14 19:48 ` Bounine, Alexandre
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=20160910214438.de89220445c47eb0d69c9f77@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=alexandre.bounine@idt.com \
--cc=khoroshilov@ispras.ru \
--cc=ldv-project@linuxtesting.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mporter@kernel.crashing.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
all inboxes | Powered by JetHome®