From patchwork Fri Sep 22 07:46:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dinghao Liu X-Patchwork-Id: 13395179 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65EA1CD4F27 for ; Fri, 22 Sep 2023 07:48:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231663AbjIVHsI (ORCPT ); Fri, 22 Sep 2023 03:48:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229647AbjIVHsH (ORCPT ); Fri, 22 Sep 2023 03:48:07 -0400 Received: from zju.edu.cn (mail.zju.edu.cn [61.164.42.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E52D4C2; Fri, 22 Sep 2023 00:47:59 -0700 (PDT) Received: from localhost.localdomain (unknown [10.181.203.255]) by mail-app3 (Coremail) with SMTP id cC_KCgDHz8OfRg1lmyKYAA--.16832S4; Fri, 22 Sep 2023 15:47:47 +0800 (CST) From: Dinghao Liu To: dinghao.liu@zju.edu.cn Cc: linux-scsi@vger.kernel.org, Steffen Maier , Benjamin Block , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , James Bottomley , Swen Schillig , Christof Schmitt , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] scsi: zfcp: Fix a double put in zfcp_port_enqueue Date: Fri, 22 Sep 2023 15:46:31 +0800 Message-Id: <20230922074631.9408-1-dinghao.liu@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: cC_KCgDHz8OfRg1lmyKYAA--.16832S4 X-Coremail-Antispam: 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M-SenderInfo: qrrzjiaqtzq6lmxovvfxof0/1tbiAgAGBmUMUaAikwAEsv Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org When device_register() fails, zfcp_port_release() will be called after put_device(). As a result, zfcp_ccw_adapter_put() will be called twice: one in zfcp_port_release() and one in the error path after device_register(). So the reference on the adapter object is doubly put, which may lead to a premature free. Fix this by adjusting the error tag after device_register(). Fixes: f3450c7b9172 ("[SCSI] zfcp: Replace local reference counting with common kref") Signed-off-by: Dinghao Liu --- Changelog: v2: -Improve the patch description. -Add a new label 'err_register' to unify code style. --- drivers/s390/scsi/zfcp_aux.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c index df782646e856..ad0ef9546501 100644 --- a/drivers/s390/scsi/zfcp_aux.c +++ b/drivers/s390/scsi/zfcp_aux.c @@ -552,7 +552,7 @@ struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn, if (device_register(&port->dev)) { put_device(&port->dev); - goto err_out; + goto err_register; } write_lock_irq(&adapter->port_list_lock); @@ -565,5 +565,6 @@ struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn, err_out: zfcp_ccw_adapter_put(adapter); +err_register: return ERR_PTR(retval); }