Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753929AbcLISah (ORCPT ); Fri, 9 Dec 2016 13:30:37 -0500 Received: from mout.web.de ([217.72.192.78]:54274 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753631AbcLISaR (ORCPT ); Fri, 9 Dec 2016 13:30:17 -0500 To: linux-raid@vger.kernel.org, Shaohua Li Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Subject: [PATCH] md: Combine two kmalloc() calls into one in sb_equal() Message-ID: Date: Fri, 9 Dec 2016 19:30:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:rS8JTXW9qNpZTz7GS+qfn8zLV25Icswaa79YqOnnWOl/rJ1lwP/ S/QG2gBo3Trey9Rb3KxmgRZSaQWShXEAQo1N+U+9QAptzYGnYjtyKnwAlXh1LB3zQTECykx ecZUTaAgoKNSMJ6i642y5dFLvydz5lC7Ki8epUJEX2R+YIXobhw5m/+ikTMYUw9lujsmjLS duo4WDsZRMVQVZsC+dDpw== X-UI-Out-Filterresults: notjunk:1;V01:K0:Ti83RqLLuro=:UJqyVXvTXCWJUEo5MMrN0A dWJRveD5qqkrZ7axhhN0hszXjtnj2HlxUAu8VZ+c2jJDAO5MNoRELMvcMDrTScG1JeV3ZVP/7 PV3K1XAWxGQcfKLImBGUeR5E9JRfH5ShszAmD7mrsLayBtFkOr2OhF+fFe4NKgVPeYflQv88b JXbfNfjv1OgqNNLvxscwzebndCJeYiqi237QztEmitT6nELiYkNmwhDyJiW8EzNDbGTpXp3hF WC9DTSHWJlV/poN98vbWEJaLPaSWZHOOHSROmDYAhc14Tcto3Ick5wsPmSW+TUzfQpLbKcEaA iShNLIT76b7scNnwxnFiB1cJtiG3ZWUm+K8wvoJorVvacJyo3WF5fLkjNoKGGStRylnjWfhOi 93bhoOAPQTJ9oZgqwWMlMZvTmDtmMtXTZHJLwqGWs9JkWX6bIU7PjFldqtUnKge0Es84l7T2w Z1vEXqEuczJgeGVyU9mBWCOJj+b1M8D2hpl0y0dQQxsUA+P0dOUdRyBJOEzmH3dmug3V2AEIk APdq01ySJqG+fz1nwvMPU5HOQS8B6eRIdYx/u1/iOP7SzED5O3pDO41MKQPA7Ue2/vNQcXlRU qVL5PXsd8zUNrdz/049VZiYbVlLhmuV8eupgbOcbbmYvaH2JDUfvtNbJnw4KXl1LVAi9EhF5a ZqRaExvHPjToK861m0N9nsx0hnSYJTPf+V/kj+cw9reuydOmuzJD8ZAtjQ+ZCnewSBihZgdux TxMSvHcoNqrA7ledySFXUe7o+eT76OI/GILKw7EsqYg0dn/tw2gAK3mM/x/If9x/kEWjOdCl4 P7DuAsw Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1354 Lines: 53 From: Markus Elfring Date: Fri, 9 Dec 2016 19:09:13 +0100 The function "kmalloc" was called in one case by the function "sb_equal" without checking immediately if it failed. This issue was detected by using the Coccinelle software. Perform the desired memory allocation (and release at the end) by a single function call instead. Fixes: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 ("Linux-2.6.12-rc2") Signed-off-by: Markus Elfring --- drivers/md/md.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index b088668269b0..86caf2536255 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -843,15 +843,12 @@ static int sb_equal(mdp_super_t *sb1, mdp_super_t *sb2) int ret; mdp_super_t *tmp1, *tmp2; - tmp1 = kmalloc(sizeof(*tmp1),GFP_KERNEL); - tmp2 = kmalloc(sizeof(*tmp2),GFP_KERNEL); - - if (!tmp1 || !tmp2) { - ret = 0; - goto abort; - } + tmp1 = kmalloc(2 * sizeof(*tmp1), GFP_KERNEL); + if (!tmp1) + return 0; *tmp1 = *sb1; + tmp2 = tmp1 + 1; *tmp2 = *sb2; /* @@ -861,9 +858,7 @@ static int sb_equal(mdp_super_t *sb1, mdp_super_t *sb2) tmp2->nr_disks = 0; ret = (memcmp(tmp1, tmp2, MD_SB_GENERIC_CONSTANT_WORDS * 4) == 0); -abort: kfree(tmp1); - kfree(tmp2); return ret; } -- 2.11.0