Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1519902pxb; Thu, 4 Nov 2021 03:56:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEv0lbgn75uiDYnzuOUKzktG+uQmVv9R7p8UkZ0ASbF1oON6vQUXKiST5kBQaQxgbU54mE X-Received: by 2002:a05:6e02:18cb:: with SMTP id s11mr667203ilu.266.1636023392924; Thu, 04 Nov 2021 03:56:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636023392; cv=none; d=google.com; s=arc-20160816; b=eCWaH8VOoTl3p7A/zn4INWajOYcX8lY0gZRz1TljBdzU5y1YM6oO59yoMAbDO9R3xb 9MQL2Tr5m5s+78w5sJfBlDuZjopEA95+TaYV9qkM51X7kF6u2eS0+pxWhCPKZfWzouj/ iego5b+64ScptnhLAOsqiYQuOw0zp/UEAehBIUWJAzKa9/bPxjFR/wRq0NeeOgXyZ5o0 05CTKqAAJpui+2l5KFcI5TC8uAwE1AlxrBoR4agRzM8wzTj5wzF28vGim5BAe3KtW9CB WT336RpEHRMkuwrmIUqvtnhwurHN22uWW3z6UT0lSkpkNE8br41QTI06t9A/357A0j7F Ps2Q== 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=j/4n1EDySbDXekdKlgVvtfUsvWplS93WM9nu5Vqbehs=; b=WOd1LqjzyYeXLbkS15lIDdQ8G0YLs4qtjExz23s0FDMHN2GBOj34zI6bWefc8faY0v +5+k7S6ijdC7PsVlD+tudan/A3/+DrMWO73RzOeNOvk+FWaeaF7MLtGJRr688FG6Ze4K x3WVTW/BQVcIkdoMWHGz7FnVPsMOZhGsqrekxnJ33oq49uh3uiBpdkq9v7VlhN94nkU4 hn4sfpcrnfwS0oDMxUMqol4rj8Xy28UjasXANfj2VIwE4nxoh8DxdiuwpFGG9R2SSngX T7SMM734DrjEvtyOQM6g7LqBWXChXLz9BrLjv4Hy2n2BzkL5WSZ8BAUr4nIWfKkTsXjQ YJdg== 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 u18si8512685jat.31.2021.11.04.03.56.19; Thu, 04 Nov 2021 03:56:32 -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 S230478AbhKDK57 (ORCPT + 99 others); Thu, 4 Nov 2021 06:57:59 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:15360 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229809AbhKDK54 (ORCPT ); Thu, 4 Nov 2021 06:57:56 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HlLBd6LdYz90fl; Thu, 4 Nov 2021 18:55:05 +0800 (CST) Received: from dggpeml500019.china.huawei.com (7.185.36.137) by dggemv704-chm.china.huawei.com (10.3.19.47) 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:55:15 +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:55:15 +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: <1bdaf8e4-319b-8dd2-9869-5bac8ffcbdf2@huawei.com> Date: Thu, 4 Nov 2021 18:55:14 +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) >