Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1521493pxb; Thu, 4 Nov 2021 03:58:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzl58l9RTc+9ZB25CibbFfgNhy6J8JWTwIEbzCVgpkNbLoHrF2wcq+5k7zRe5EZ/C0kvxzb X-Received: by 2002:a05:6e02:19c8:: with SMTP id r8mr4864106ill.47.1636023521035; Thu, 04 Nov 2021 03:58:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636023521; cv=none; d=google.com; s=arc-20160816; b=0JuiURJkll0nbQdpiUAFmz18Ef1pFeMOArVDu4BrUG4VSycCI2oh8r+psF+2mHTi4I 5uW6o+dq5bpr/WxwZ7byQqiaYRjeGIba55TVNxSvLid4ni6HcHYh9CSGr/Emp7JEk40O QzfYZV5WE+Sp96dtO2A0J1RQ7fSGi5/5Fk+dG9bnluYz5lquD77Hg20FtpcdWQrDAKM3 iq6SQush8tpvHM3xDbdyi9Sx0Nvo6s5A/BkvGSum7p3yquuM3MJ4NtQTGxInraETMPXK YrGPEUNIeqwa0JVwMV77rhFEDVn2e5fMVBkFoUDUrAZUNTaxPOLoMJ/zclD7YMrVUEf0 zP9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=03ltibmDz5Jvv4GIk2+jq8NmoVs/hpNj0se/L9AieAg=; b=QD4dEEzZ4q5v99bYnBWRtNjyAtCFJfg9ZKi00IKRGBmds1ByLxiuk6YcEykezc4TPj A34R6U72UZguMevk5K4oBt5POcwyYwp0V3aoLoGeGp3XlTwmkAdCK+6Ja3gWS/3po8iw BegwAZnKE0A/MOC9/UZ7wnoYJxdzidUYAL4Z9Ypt+C8f4SV7Q9yonHZG8z9K5wLOI60X VCfc4XLP6t5xXahMegHxxpTTCx6Sb/ZlU+PqcZmBlmhThapWsVeuCEKXOk1iKV1Q8m4r Biah8F/HIIOfC75WxJAqjJhKcXjbNJpSwpFlYQfdhmY1X1RhUMU3JMnxuik/gGymQWYK 67Jw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j9si10423903ils.179.2021.11.04.03.58.26; Thu, 04 Nov 2021 03:58:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231254AbhKDK7v (ORCPT + 99 others); Thu, 4 Nov 2021 06:59:51 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:14716 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230511AbhKDK7v (ORCPT ); Thu, 4 Nov 2021 06:59:51 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HlLBc56z7zZcYd; Thu, 4 Nov 2021 18:55:04 +0800 (CST) Received: from dggpeml500019.china.huawei.com (7.185.36.137) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Thu, 4 Nov 2021 18:57:11 +0800 Received: from [10.174.179.189] (10.174.179.189) by dggpeml500019.china.huawei.com (7.185.36.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Thu, 4 Nov 2021 18:57:10 +0800 Subject: Re: [PATCH] block: fix device_add_disk() kobject_create_and_add() error handling To: Luis Chamberlain , , , CC: , , "kernel test robot" , Dan Carpenter References: <20211103164023.1384821-1-mcgrof@kernel.org> From: Wu Bo Message-ID: <143998a3-6c53-77f0-ef8c-af428ac64001@huawei.com> Date: Thu, 4 Nov 2021 18:57:10 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.2.2 MIME-Version: 1.0 In-Reply-To: <20211103164023.1384821-1-mcgrof@kernel.org> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.189] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500019.china.huawei.com (7.185.36.137) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/11/4 0:40, Luis Chamberlain wrote: > Commit 83cbce957446 ("block: add error handling for device_add_disk / > add_disk") added error handling to device_add_disk(), however the goto > label for the kobject_create_and_add() failure did not set the return > value correctly, and so we can end up in a situation where > kobject_create_and_add() fails but we report success. > > Fixes: 83cbce957446 ("block: add error handling for device_add_disk / add_disk") > Reported-by: kernel test robot > Reported-by: Dan Carpenter > Signed-off-by: Luis Chamberlain > --- > block/genhd.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/block/genhd.c b/block/genhd.c > index be4775c13760..b0b484116c3a 100644 > --- a/block/genhd.c > +++ b/block/genhd.c > @@ -478,8 +478,10 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, > if (!disk->part0->bd_holder_dir) in here also should be add ret = -ENOMEM; > goto out_del_integrity; > disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj); > - if (!disk->slave_dir) > + if (!disk->slave_dir) { > + ret = -ENOMEM; > goto out_put_holder_dir; > + } > > ret = bd_register_pending_holders(disk); > if (ret < 0) >