linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Douglas Gilbert <dgilbert@interlog.com>
To: linux-scsi@vger.kernel.org
Cc: James.Bottomley@HansenPartnership.com,
	martin.petersen@oracle.com, bart.vanassche@sandisk.com
Subject: [PATCH] scsi_debug: fix sleep in invalid context
Date: Mon, 30 May 2016 14:19:07 -0400	[thread overview]
Message-ID: <1464632347-8621-1-git-send-email-dgilbert@interlog.com> (raw)

In this post: http://www.spinics.net/lists/linux-scsi/msg97124.html
the author shows some kernel infrastructure complaining about a
sleep in an invalid context. For calls to fetch memory when
processing SCSI commands, reviewers often propose non GFP_ATOMIC
variants; reality dictates otherwise. Fix memory allocation for
response to REPORT LUNS command.

Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
---
 drivers/scsi/scsi_debug.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 0f9ba41..b85c5dc 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -3331,13 +3331,12 @@ static int resp_report_luns(struct scsi_cmnd *scp,
 	tlun_cnt = lun_cnt + wlun_cnt;
 
 	rlen = (tlun_cnt * sizeof(struct scsi_lun)) + 8;
-	arr = vmalloc(rlen);
+	arr = kzalloc(rlen, GFP_ATOMIC);
 	if (!arr) {
 		mk_sense_buffer(scp, ILLEGAL_REQUEST, INSUFF_RES_ASC,
 				INSUFF_RES_ASCQ);
 		return check_condition_result;
 	}
-	memset(arr, 0, rlen);
 	pr_debug("select_report %d luns = %d wluns = %d no_lun0 %d\n",
 		 select_report, lun_cnt, wlun_cnt, sdebug_no_lun_0);
 
@@ -3355,7 +3354,7 @@ static int resp_report_luns(struct scsi_cmnd *scp,
 	put_unaligned_be32(rlen - 8, &arr[0]);
 
 	res = fill_from_dev_buffer(scp, arr, rlen);
-	vfree(arr);
+	kfree(arr);
 	return res;
 }
 
-- 
2.7.4


             reply	other threads:[~2016-05-30 18:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-30 18:19 Douglas Gilbert [this message]
2016-05-30 19:02 ` [PATCH] scsi_debug: fix sleep in invalid context James Bottomley
2016-05-30 19:09   ` Christoph Hellwig
2016-05-31 21:12     ` Douglas Gilbert

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=1464632347-8621-1-git-send-email-dgilbert@interlog.com \
    --to=dgilbert@interlog.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=bart.vanassche@sandisk.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@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 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).