Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2192555rdb; Fri, 8 Dec 2023 00:25:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4ulHpt/j0TfeS/vNjrqwvkLDBzFkwO6CjRABTlkAc8kX8yiOpkPdgAkKZxmdyPv955sAe X-Received: by 2002:a05:6a00:198b:b0:6ce:78c9:5979 with SMTP id d11-20020a056a00198b00b006ce78c95979mr818164pfl.18.1702023905431; Fri, 08 Dec 2023 00:25:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702023905; cv=none; d=google.com; s=arc-20160816; b=00/hLMHohLOS48940hGhhNffaDDkvvD6oSR8n9nYJ11j+/4gsbKp8odYs0TYOKukx3 W2dwcTUSLgG4zdKaKVmvrPmzQ9PttPqO1vE0wjkg1tmdL774RztK0n1jEkITYr7fyzxp sGUqOGwZx2oapBytFszW8qjbJXJ5YNWM6W169Sr3D/X3ll1/5iVrU+elJusMz+UMDobD G3+JdAxIDz4KuHRC7yUttCSksWIBjlPRjTzKUa8pxfJIrJkcWUpiWyZuwtJHO82V7JHw D1/Yw78E84oLgHMtAoV6CiPE+UQMzYH3PgW+t8AfJ2uFAuXWfLzrBtstcsFrFuma2MPI 9Mfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=6fBTftYonsRWKNtNI2DhUSxq3v5TFdhih75o14Lf9I0=; fh=7RYUT2J5p7ROu5PBaPpATDCV5+4ZOf67qrQniqToYqw=; b=vCfrLRH6tvUbFQGvARybNU8TxSf/CVHVw12+kQQ2A4MSohTp6JaaXdYpllnImu782G hDtl4WjO/H1grm1s/ExGfR6EObH+C79OBbsueLf5SmzikEceZ9YLcTz219GkIkyOIvgb rqgU/gh+gjFM9hkawmB9adzApia1/pRcpZyeswmNm0a8M3oDT8wMfgnYwlSHx8IH7wB5 Gqu94BQBrUvy05VOZHII/oc5rzj1S7vuUbHMZQgNLKYbBjoHpirB1x43ST+iK8B7ogfN XxCMHJm6tlvgIYRYCIN+Rtusc/tdrRk/oiJZ1KBkv/8CN7BWLOuIaJqtH0E3r6kpqfoC hUFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id b19-20020a056a000a9300b006cddbffdae6si1155621pfl.353.2023.12.08.00.25.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 00:25:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id C5CD880F6484; Fri, 8 Dec 2023 00:25:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573275AbjLHIYs (ORCPT + 99 others); Fri, 8 Dec 2023 03:24:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232974AbjLHIYr (ORCPT ); Fri, 8 Dec 2023 03:24:47 -0500 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60AF61724; Fri, 8 Dec 2023 00:24:53 -0800 (PST) Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4SmkhX66PQz4f3l1b; Fri, 8 Dec 2023 16:24:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id A0D891A09BD; Fri, 8 Dec 2023 16:24:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgDHyhDP0nJlmB1EDA--.42879S4; Fri, 08 Dec 2023 16:24:49 +0800 (CST) From: linan666@huaweicloud.com To: jejb@linux.ibm.com, martin.petersen@oracle.com, mcgrof@kernel.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linan122@huawei.com, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH] scsi: sd: unregister device if device_add_disk() failed in sd_probe() Date: Fri, 8 Dec 2023 16:23:35 +0800 Message-Id: <20231208082335.1754205-1-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: cCh0CgDHyhDP0nJlmB1EDA--.42879S4 X-Coremail-Antispam: 1UD129KBjvdXoW7JFWxXr13GryDXw1DZry7ZFb_yoWfArg_Ca 12v39rXr1rCr1xtw1fAr1avrW0vF42qrW5Cr4jqF9ava15WryvgF909r1Fvr4UGF17uw1U tr1jqr4Fyr4kKjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUba8YFVCjjxCrM7AC8VAFwI0_Gr0_Xr1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwV A0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x02 67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I 0E14v26rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l 5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67 AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7Cj xVA2Y2ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4 AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE 17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMI IF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Wr1j6rW3 Jr1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcS sGvfC2KfnxnUUI43ZEXa7IUbEAp5UUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 08 Dec 2023 00:25:02 -0800 (PST) From: Li Nan "if device_add() succeeds, you should call device_del() when you want to get rid of it." In sd_probe(), device_add_disk() fails when device_add() has already succeeded, so change put_device() to device_unregister() to ensure device resources are released. Fixes: 2a7a891f4c40 ("scsi: sd: Add error handling support for add_disk()") Signed-off-by: Li Nan --- drivers/scsi/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 542a4bbb21bc..d81cbeee06eb 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3736,7 +3736,7 @@ static int sd_probe(struct device *dev) error = device_add_disk(dev, gd, NULL); if (error) { - put_device(&sdkp->disk_dev); + device_unregister(&sdkp->disk_dev); put_disk(gd); goto out; } -- 2.39.2