Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758397AbcDMGrF (ORCPT ); Wed, 13 Apr 2016 02:47:05 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:41421 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756012AbcDMGrC (ORCPT ); Wed, 13 Apr 2016 02:47:02 -0400 Date: Wed, 13 Apr 2016 09:46:45 +0300 From: Dan Carpenter To: Shaohua Li , Krzysztof Wojcik Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch] md/raid0: check for create_strip_zones() errors Message-ID: <20160413064645.GH8092@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1877 Lines: 66 My static checker complains that if create_strip_zones() fails then we use "priv_conf" without initializing it. Fix this by checking for failure. Signed-off-by: Dan Carpenter diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c index 2ea12c6..1d80e3c 100644 --- a/drivers/md/raid0.c +++ b/drivers/md/raid0.c @@ -507,6 +507,7 @@ static void *raid0_takeover_raid45(struct mddev *mddev) { struct md_rdev *rdev; struct r0conf *priv_conf; + int ret; if (mddev->degraded != 1) { printk(KERN_ERR "md/raid0:%s: raid5 must be degraded! Degraded disks: %d\n", @@ -534,13 +535,16 @@ static void *raid0_takeover_raid45(struct mddev *mddev) /* make sure it will be not marked as dirty */ mddev->recovery_cp = MaxSector; - create_strip_zones(mddev, &priv_conf); + ret = create_strip_zones(mddev, &priv_conf); + if (ret) + return ERR_PTR(ret); return priv_conf; } static void *raid0_takeover_raid10(struct mddev *mddev) { struct r0conf *priv_conf; + int ret; /* Check layout: * - far_copies must be 1 @@ -575,7 +579,9 @@ static void *raid0_takeover_raid10(struct mddev *mddev) /* make sure it will be not marked as dirty */ mddev->recovery_cp = MaxSector; - create_strip_zones(mddev, &priv_conf); + ret = create_strip_zones(mddev, &priv_conf); + if (ret) + return ERR_PTR(ret); return priv_conf; } @@ -583,6 +589,7 @@ static void *raid0_takeover_raid1(struct mddev *mddev) { struct r0conf *priv_conf; int chunksect; + int ret; /* Check layout: * - (N - 1) mirror drives must be already faulty @@ -617,7 +624,9 @@ static void *raid0_takeover_raid1(struct mddev *mddev) /* make sure it will be not marked as dirty */ mddev->recovery_cp = MaxSector; - create_strip_zones(mddev, &priv_conf); + ret = create_strip_zones(mddev, &priv_conf); + if (ret) + return ERR_PTR(ret); return priv_conf; }