From patchwork Fri Dec 2 16:46:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 29008 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp963408wrr; Fri, 2 Dec 2022 08:50:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf6cz0or+ln+0Uszst6YLchE9orZ0Iu5oXu0SgLF1pZQBffFWBYULG2+1zRA52RgdVMlzb8y X-Received: by 2002:a17:902:be01:b0:186:7db1:d2a4 with SMTP id r1-20020a170902be0100b001867db1d2a4mr56650121pls.84.1669999853779; Fri, 02 Dec 2022 08:50:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669999853; cv=none; d=google.com; s=arc-20160816; b=mZGiy+FCnY+JbChS869hptUyO15rLgh2+hm2h9it8tNVVODytwiAr2kHGVUBDMOr5w YL89EmAG1NeUvZiJF491ykSlKl/brWEYr9CGhK/xCJr++RZ6xjzDatCYKgOnO92uiy1z wBmNN9Ig8OcLIPxx7KvePwPe//ZyQZxMzFIaibQR4vmvo/p2RGvGlxUGvrPOgg2ADCQF VxLNyksJ65Gl0KJ3xDcl3SFoCMokSgqIo4Uy5M42F1pDjQ7YqZnDBD80Yc01M70z6aNz LsGOtoIVEb3SNr4Wgtu1P9JQc+G0ICGTqNqgl3H0OS4VfiAWCYKRoRSgfDPraHKbsMJL F0Sw== 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 :user-agent:message-id:date:cc:to:from:subject:dkim-signature; bh=bDZB9/UWBP2K8rOod3EiStKnFBOCd1JU4UtUL2I7L4s=; b=KCfgIpJNN0Jf7hxI/yu3bF6zPb3mMjQ9vLXBaC/pmMccnxrPFBM8W1ca8Lmkl8kXA5 UGEyvaTRzXmf5QZ1anJuC69Ntafrt+rPsWth5ao4yFsmK+7liveibQUKRGTDRGARDMY0 UYxCivRYmYY1ZXPYVGIIjCyjGuK1v90O3/hHF8f6NaRCIuJaZ9b+nC3RtHHqM7mlVydj 9CBwhrjmFJv0HnCxZFB9jG0/VZra3yWH2cPTlSJGEYSMFkzWJ97yXe5doYJI3GL0w1S0 leVbIx28kUfhkqkXDKR1sEYvkfFE6DeJfn1XEnA2x5mlOhOFx8yTOapn5gXpa3MkL9zD cCMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ANqPx6KZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w15-20020a1709027b8f00b00189c4a9c5ecsi173093pll.297.2022.12.02.08.50.19; Fri, 02 Dec 2022 08:50:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ANqPx6KZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234041AbiLBQrY (ORCPT + 99 others); Fri, 2 Dec 2022 11:47:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233375AbiLBQrV (ORCPT ); Fri, 2 Dec 2022 11:47:21 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C664C82DE for ; Fri, 2 Dec 2022 08:46:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669999581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=bDZB9/UWBP2K8rOod3EiStKnFBOCd1JU4UtUL2I7L4s=; b=ANqPx6KZdDKdJh9GaI+ZanZMIhX2k/k50sI9kA+Xz4cOVKW80za4iXAj3Go8oroqArsDES 19AowtL1AKAb9XZlV/y4gQw3RV12KzVf2Ui+ZTgOGKw26CmfqixzQ4DOqoroelHDIBRElQ +BYnixGxJSpWafv1TjF5u5PO040+Fck= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-3-Qi2ujFK3NKW2JVwfSMsgOw-1; Fri, 02 Dec 2022 11:46:18 -0500 X-MC-Unique: Qi2ujFK3NKW2JVwfSMsgOw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 216C41C06EE6; Fri, 2 Dec 2022 16:46:18 +0000 (UTC) Received: from [172.30.42.193] (unknown [10.22.33.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63EDD1410DDA; Fri, 2 Dec 2022 16:46:17 +0000 (UTC) Subject: [PATCH] vfio/ap/ccw/samples: Fix device_register() unwind path From: Alex Williamson To: alex.williamson@redhat.com Cc: ruanjinjie , Tony Krowiak , Halil Pasic , Jason Herne , Kirti Wankhede , Kevin Tian , Eric Farman , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 02 Dec 2022 09:46:15 -0700 Message-ID: <166999942139.645727.12439756512449846442.stgit@omen> User-Agent: StGit/1.5.dev2+g9ce680a52bd9 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751121766628751937?= X-GMAIL-MSGID: =?utf-8?q?1751121766628751937?= We always need to call put_device() if device_register() fails. All vfio drivers calling device_register() include a similar unwind stack via gotos, therefore split device_unregister() into its device_del() and put_device() components in the unwind path, and add a goto target to handle only the put_device() requirement. Reported-by: Ruan Jinjie Link: https://lore.kernel.org/all/20221118032827.3725190-1-ruanjinjie@huawei.com Fixes: d61fc96f47fd ("sample: vfio mdev display - host device") Fixes: 9d1a546c53b4 ("docs: Sample driver to demonstrate how to use Mediated device framework.") Fixes: a5e6e6505f38 ("sample: vfio bochs vbe display (host device for bochs-drm)") Fixes: 9e6f07cd1eaa ("vfio/ccw: create a parent struct") Fixes: 36360658eb5a ("s390: vfio_ap: link the vfio_ap devices to the vfio_ap bus subsystem") Cc: Tony Krowiak Cc: Halil Pasic Cc: Jason Herne Cc: Kirti Wankhede Reviewed-by: Kevin Tian Reviewed-by: Eric Farman Signed-off-by: Alex Williamson Reviewed-by: Jason J. Herne Reviewed-by: Tony Krowiak Reviewed-by: Halil Pasic --- I didn't intend to usurp Ruan's patch, but since the inline version is collecting reviews, formally post it and include additional fixes tags for vfio-ccw and vfio-ap. drivers/s390/cio/vfio_ccw_drv.c | 3 ++- drivers/s390/crypto/vfio_ap_drv.c | 2 +- samples/vfio-mdev/mbochs.c | 7 ++++--- samples/vfio-mdev/mdpy.c | 7 ++++--- samples/vfio-mdev/mtty.c | 7 ++++--- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index c2a65808605a..54aba7cceb33 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -199,8 +199,9 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) return 0; out_unreg: - device_unregister(&parent->dev); + device_del(&parent->dev); out_free: + put_device(&parent->dev); dev_set_drvdata(&sch->dev, NULL); return ret; } diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c index f43cfeabd2cc..997b524bdd2b 100644 --- a/drivers/s390/crypto/vfio_ap_drv.c +++ b/drivers/s390/crypto/vfio_ap_drv.c @@ -122,7 +122,7 @@ static int vfio_ap_matrix_dev_create(void) return 0; matrix_drv_err: - device_unregister(&matrix_dev->device); + device_del(&matrix_dev->device); matrix_reg_err: put_device(&matrix_dev->device); matrix_alloc_err: diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index 8b5a3a778a25..e54eb752e1ba 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1430,7 +1430,7 @@ static int __init mbochs_dev_init(void) ret = device_register(&mbochs_dev); if (ret) - goto err_class; + goto err_put; ret = mdev_register_parent(&mbochs_parent, &mbochs_dev, &mbochs_driver, mbochs_mdev_types, @@ -1441,8 +1441,9 @@ static int __init mbochs_dev_init(void) return 0; err_device: - device_unregister(&mbochs_dev); -err_class: + device_del(&mbochs_dev); +err_put: + put_device(&mbochs_dev); class_destroy(mbochs_class); err_driver: mdev_unregister_driver(&mbochs_driver); diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index 721fb06c6413..e8400fdab71d 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -717,7 +717,7 @@ static int __init mdpy_dev_init(void) ret = device_register(&mdpy_dev); if (ret) - goto err_class; + goto err_put; ret = mdev_register_parent(&mdpy_parent, &mdpy_dev, &mdpy_driver, mdpy_mdev_types, @@ -728,8 +728,9 @@ static int __init mdpy_dev_init(void) return 0; err_device: - device_unregister(&mdpy_dev); -err_class: + device_del(&mdpy_dev); +err_put: + put_device(&mdpy_dev); class_destroy(mdpy_class); err_driver: mdev_unregister_driver(&mdpy_driver); diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index 3c2a421b9b69..e887de672c52 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -1330,7 +1330,7 @@ static int __init mtty_dev_init(void) ret = device_register(&mtty_dev.dev); if (ret) - goto err_class; + goto err_put; ret = mdev_register_parent(&mtty_dev.parent, &mtty_dev.dev, &mtty_driver, mtty_mdev_types, @@ -1340,8 +1340,9 @@ static int __init mtty_dev_init(void) return 0; err_device: - device_unregister(&mtty_dev.dev); -err_class: + device_del(&mtty_dev.dev); +err_put: + put_device(&mtty_dev.dev); class_destroy(mtty_dev.vd_class); err_driver: mdev_unregister_driver(&mtty_driver);