From: SF Markus Elfring <elfring@users.sourceforge.net>
To: esc.storagedev@microsemi.com, iss_storagedev@hp.com,
linux-scsi@vger.kernel.org, Don Brace <don.brace@microsemi.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org,
Julia Lawall <julia.lawall@lip6.fr>
Subject: [PATCH 2/5] block-cciss: Less function calls in cciss_bigpassthru() after error detection
Date: Thu, 18 Aug 2016 11:56:44 +0200 [thread overview]
Message-ID: <d6586ebd-7422-4188-2a5b-af314e06f411@users.sourceforge.net> (raw)
In-Reply-To: <686a1f95-a76c-2624-50e1-9d0e59948e64@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 17 Aug 2016 22:39:31 +0200
The kfree() function was called in a few cases by the
cciss_bigpassthru() function during error handling
even if a passed variable contained a null pointer.
Adjust jump targets according to the Linux coding style convention.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/block/cciss.c | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index e044342..43ac632 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -1593,26 +1593,26 @@ static int cciss_bigpassthru(ctlr_info_t *h, void __user *argp)
if ((ioc->buf_size < 1) &&
(ioc->Request.Type.Direction != XFER_NONE)) {
status = -EINVAL;
- goto cleanup1;
+ goto free_ioc;
}
/* Check kmalloc limits using all SGs */
if (ioc->malloc_size > MAX_KMALLOC_SIZE) {
status = -EINVAL;
- goto cleanup1;
+ goto free_ioc;
}
if (ioc->buf_size > ioc->malloc_size * MAXSGENTRIES) {
status = -EINVAL;
- goto cleanup1;
- }
- buff = kzalloc(MAXSGENTRIES * sizeof(char *), GFP_KERNEL);
- if (!buff) {
- status = -ENOMEM;
- goto cleanup1;
+ goto free_ioc;
}
buff_size = kmalloc(MAXSGENTRIES * sizeof(int), GFP_KERNEL);
if (!buff_size) {
status = -ENOMEM;
- goto cleanup1;
+ goto free_ioc;
+ }
+ buff = kzalloc(MAXSGENTRIES * sizeof(char *), GFP_KERNEL);
+ if (!buff) {
+ status = -ENOMEM;
+ goto free_size;
}
left = ioc->buf_size;
data_ptr = ioc->buf;
@@ -1622,12 +1622,12 @@ static int cciss_bigpassthru(ctlr_info_t *h, void __user *argp)
buff[sg_used] = kmalloc(sz, GFP_KERNEL);
if (buff[sg_used] == NULL) {
status = -ENOMEM;
- goto cleanup1;
+ goto free_buffer;
}
if (ioc->Request.Type.Direction == XFER_WRITE) {
if (copy_from_user(buff[sg_used], data_ptr, sz)) {
status = -EFAULT;
- goto cleanup1;
+ goto free_buffer;
}
} else {
memset(buff[sg_used], 0, sz);
@@ -1639,7 +1639,7 @@ static int cciss_bigpassthru(ctlr_info_t *h, void __user *argp)
c = cmd_special_alloc(h);
if (!c) {
status = -ENOMEM;
- goto cleanup1;
+ goto free_buffer;
}
c->cmd_type = CMD_IOCTL_PEND;
c->Header.ReplyQueue = 0;
@@ -1674,7 +1674,7 @@ static int cciss_bigpassthru(ctlr_info_t *h, void __user *argp)
if (copy_to_user(argp, ioc, sizeof(*ioc))) {
cmd_special_free(h, c);
status = -EFAULT;
- goto cleanup1;
+ goto free_buffer;
}
if (ioc->Request.Type.Direction == XFER_READ) {
/* Copy the data out of the buffer we created */
@@ -1683,20 +1683,20 @@ static int cciss_bigpassthru(ctlr_info_t *h, void __user *argp)
if (copy_to_user(ptr, buff[i], buff_size[i])) {
cmd_special_free(h, c);
status = -EFAULT;
- goto cleanup1;
+ goto free_buffer;
}
ptr += buff_size[i];
}
}
cmd_special_free(h, c);
status = 0;
-cleanup1:
- if (buff) {
- for (i = 0; i < sg_used; i++)
- kfree(buff[i]);
- kfree(buff);
- }
+free_buffer:
+ for (i = 0; i < sg_used; i++)
+ kfree(buff[i]);
+ kfree(buff);
+free_size:
kfree(buff_size);
+free_ioc:
kfree(ioc);
return status;
}
--
2.9.3
next prev parent reply other threads:[~2016-08-18 9:56 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <566ABCD9.1060404@users.sourceforge.net>
2015-12-12 14:30 ` [PATCH 0/7] iSCSI-target: Fine-tuning for three function implementations SF Markus Elfring
2015-12-12 14:34 ` [PATCH 1/7] iscsi-target: Use a variable initialisation in iscsi_set_default_param() directly SF Markus Elfring
2015-12-12 19:49 ` Dan Carpenter
2015-12-12 21:22 ` SF Markus Elfring
2015-12-14 8:41 ` Johannes Thumshirn
2015-12-14 11:38 ` SF Markus Elfring
2015-12-12 14:37 ` [PATCH 2/7] iscsi-target: Less checks in iscsi_set_default_param() after error detection SF Markus Elfring
2015-12-12 14:40 ` [PATCH 3/7] iscsi-target: Delete an unnecessary variable initialisation in iscsi_create_default_params() SF Markus Elfring
2015-12-12 14:41 ` [PATCH 4/7] iscsi-target: Make a variable initialisation a bit more obvious " SF Markus Elfring
2015-12-12 14:45 ` Julia Lawall
2015-12-12 15:02 ` SF Markus Elfring
2015-12-12 14:42 ` [PATCH 5/7] iscsi-target: Rename a jump label " SF Markus Elfring
2015-12-12 14:43 ` [PATCH 6/7] iscsi-target: Delete unnecessary variable initialisations in iscsi_check_valuelist_for_support() SF Markus Elfring
2015-12-12 14:45 ` [PATCH 7/7] iscsi-target: Make two variable initialisations a bit more obvious " SF Markus Elfring
2015-12-12 17:17 ` walter harms
2016-08-18 9:48 ` [PATCH 0/5] block-cciss: Fine-tuning for two function implementations SF Markus Elfring
2016-08-18 9:55 ` [PATCH 1/5] block-cciss: Use memdup_user() rather than duplicating its implementation SF Markus Elfring
2016-08-18 9:56 ` SF Markus Elfring [this message]
2016-08-18 10:00 ` [PATCH 3/5] block-cciss: Delete unnecessary initialisations in cciss_bigpassthru() SF Markus Elfring
2016-08-18 10:02 ` [PATCH 4/5] block-cciss: Move an assignment for the variable "sg_used" " SF Markus Elfring
2016-08-18 10:03 ` [PATCH 5/5] block-cciss: Replace three kzalloc() calls by kcalloc() SF Markus Elfring
2017-08-06 15:00 ` [PATCH 0/5] block-cciss: Fine-tuning for two function implementations SF Markus Elfring
2016-08-21 7:14 ` [PATCH 0/7] aacraid: Fine-tuning for a few functions SF Markus Elfring
2016-08-21 7:19 ` [PATCH 1/7] aacraid: Use memdup_user() rather than duplicating its implementation SF Markus Elfring
2016-08-22 18:00 ` David Carroll
2016-08-22 20:23 ` SF Markus Elfring
2016-08-24 23:01 ` David Carroll
2016-08-21 7:20 ` [PATCH 2/7] aacraid: One function call less in aac_send_raw_srb() after error detection SF Markus Elfring
2016-08-21 7:22 ` [PATCH 3/7] aacraid: Delete unnecessary initialisations in aac_send_raw_srb() SF Markus Elfring
2016-08-21 7:24 ` [PATCH 4/7] aacraid: Delete unnecessary braces SF Markus Elfring
2016-08-21 7:25 ` [PATCH 5/7] aacraid: Add spaces after control flow keywords SF Markus Elfring
2016-08-21 7:27 ` [PATCH 6/7] aacraid: Improve determination of a few sizes SF Markus Elfring
2016-08-21 7:29 ` [PATCH 7/7] aacraid: Apply another recommendation from "checkpatch.pl" SF Markus Elfring
2016-08-21 8:48 ` [PATCH] megaraid_sas: Use memdup_user() rather than duplicating its implementation SF Markus Elfring
2016-08-22 9:31 ` Sumit Saxena
2016-08-24 2:47 ` Martin K. Petersen
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=d6586ebd-7422-4188-2a5b-af314e06f411@users.sourceforge.net \
--to=elfring@users.sourceforge.net \
--cc=don.brace@microsemi.com \
--cc=esc.storagedev@microsemi.com \
--cc=iss_storagedev@hp.com \
--cc=julia.lawall@lip6.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.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).