From owner-dev-commits-src-branches@freebsd.org Fri Apr 23 11:14:44 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id DCBF95EE117; Fri, 23 Apr 2021 11:14:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FRWsJ3tCCz4WpH; Fri, 23 Apr 2021 11:14:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0148144A9; Fri, 23 Apr 2021 11:14:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 13NBEhq8012762; Fri, 23 Apr 2021 11:14:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 13NBEhhO012761; Fri, 23 Apr 2021 11:14:43 GMT (envelope-from git) Date: Fri, 23 Apr 2021 11:14:43 GMT Message-Id: <202104231114.13NBEhhO012761@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 9c410fc7ce11 - stable/13 - linuxkpi: drop single-use variable MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 9c410fc7ce116dfabf3ebd246bbfb416699a2a40 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Apr 2021 11:14:45 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=9c410fc7ce116dfabf3ebd246bbfb416699a2a40 commit 9c410fc7ce116dfabf3ebd246bbfb416699a2a40 Author: Konstantin Belousov AuthorDate: 2021-03-30 08:46:42 +0000 Commit: Konstantin Belousov CommitDate: 2021-04-23 11:14:06 +0000 linuxkpi: drop single-use variable (cherry picked from commit 8011fb795baa59ba14371d6db5ab661a5db77615) --- sys/compat/linuxkpi/common/src/linux_compat.c | 4 +-- sys/compat/linuxkpi/common/src/linux_compat.c.orig | 31 ++++++++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index f8b939a5ec16..8fe4f4509571 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -2224,16 +2224,14 @@ linux_cdev_static_release(struct kobject *kobj) { struct cdev *cdev; struct linux_cdev *ldev; - struct kobject *parent; ldev = container_of(kobj, struct linux_cdev, kobj); - parent = kobj->parent; cdev = ldev->cdev; if (cdev != NULL) { destroy_dev(cdev); ldev->cdev = NULL; } - kobject_put(parent); + kobject_put(kobj->parent); } void diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c.orig b/sys/compat/linuxkpi/common/src/linux_compat.c.orig index 71ea7e0844dc..28413c59bb76 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c.orig +++ b/sys/compat/linuxkpi/common/src/linux_compat.c.orig @@ -717,15 +717,19 @@ linux_get_fop(struct linux_file *filp, const struct file_operations **fop, ldev = filp->f_cdev; *fop = filp->f_op; if (ldev != NULL) { - for (siref = ldev->siref;;) { - if ((siref & LDEV_SI_DTR) != 0) { - ldev = &dummy_ldev; - siref = ldev->siref; - *fop = ldev->ops; - MPASS((ldev->siref & LDEV_SI_DTR) == 0); - } else if (atomic_fcmpset_int(&ldev->siref, &siref, - siref + LDEV_SI_REF)) { - break; + if (ldev->kobj.ktype == &linux_cdev_static_ktype) { + refcount_acquire(&ldev->refs); + } else { + for (siref = ldev->siref;;) { + if ((siref & LDEV_SI_DTR) != 0) { + ldev = &dummy_ldev; + *fop = ldev->ops; + siref = ldev->siref; + MPASS((ldev->siref & LDEV_SI_DTR) == 0); + } else if (atomic_fcmpset_int(&ldev->siref, + &siref, siref + LDEV_SI_REF)) { + break; + } } } } @@ -738,8 +742,13 @@ linux_drop_fop(struct linux_cdev *ldev) if (ldev == NULL) return; - MPASS((ldev->siref & ~LDEV_SI_DTR) != 0); - atomic_subtract_int(&ldev->siref, LDEV_SI_REF); + if (ldev->kobj.ktype == &linux_cdev_static_ktype) { + linux_cdev_deref(ldev); + } else { + MPASS(ldev->kobj.ktype == &linux_cdev_ktype); + MPASS((ldev->siref & ~LDEV_SI_DTR) != 0); + atomic_subtract_int(&ldev->siref, LDEV_SI_REF); + } } #define OPW(fp,td,code) ({ \