From owner-svn-src-all@freebsd.org Thu Dec 31 11:27:37 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8C4EBA5787D; Thu, 31 Dec 2015 11:27:37 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4629E1D2E; Thu, 31 Dec 2015 11:27:37 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tBVBRaCQ076298; Thu, 31 Dec 2015 11:27:36 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tBVBRasi076295; Thu, 31 Dec 2015 11:27:36 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201512311127.tBVBRasi076295@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 31 Dec 2015 11:27:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r292986 - in head/sys/compat/linuxkpi/common: include/linux src X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Dec 2015 11:27:37 -0000 Author: hselasky Date: Thu Dec 31 11:27:36 2015 New Revision: 292986 URL: https://svnweb.freebsd.org/changeset/base/292986 Log: Make the kobject refcounting compliant with Linux. Refcounting on the parent kobject cannot be factored out and must be done by the kobject consumers. MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/compat/linuxkpi/common/include/linux/cdev.h head/sys/compat/linuxkpi/common/src/linux_compat.c Modified: head/sys/compat/linuxkpi/common/include/linux/cdev.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/cdev.h Thu Dec 31 11:25:45 2015 (r292985) +++ head/sys/compat/linuxkpi/common/include/linux/cdev.h Thu Dec 31 11:27:36 2015 (r292986) @@ -54,21 +54,27 @@ static inline void cdev_release(struct kobject *kobj) { struct linux_cdev *cdev; + struct kobject *parent; cdev = container_of(kobj, struct linux_cdev, kobj); + parent = kobj->parent; if (cdev->cdev) destroy_dev(cdev->cdev); kfree(cdev); + kobject_put(parent); } static inline void cdev_static_release(struct kobject *kobj) { struct linux_cdev *cdev; + struct kobject *parent; cdev = container_of(kobj, struct linux_cdev, kobj); + parent = kobj->parent; if (cdev->cdev) destroy_dev(cdev->cdev); + kobject_put(parent); } static struct kobj_type cdev_ktype = { @@ -114,6 +120,7 @@ cdev_add(struct linux_cdev *cdev, dev_t cdev->dev = dev; cdev->cdev->si_drv1 = cdev; + kobject_get(cdev->kobj.parent); return (0); } Modified: head/sys/compat/linuxkpi/common/src/linux_compat.c ============================================================================== --- head/sys/compat/linuxkpi/common/src/linux_compat.c Thu Dec 31 11:25:45 2015 (r292985) +++ head/sys/compat/linuxkpi/common/src/linux_compat.c Thu Dec 31 11:27:36 2015 (r292986) @@ -157,7 +157,7 @@ kobject_add_complete(struct kobject *kob struct kobj_type *t; int error; - kobj->parent = kobject_get(parent); + kobj->parent = parent; error = sysfs_create_dir(kobj); if (error == 0 && kobj->ktype && kobj->ktype->default_attrs) { struct attribute **attr; @@ -198,9 +198,6 @@ kobject_release(struct kref *kref) kobj = container_of(kref, struct kobject, kref); sysfs_remove_dir(kobj); - if (kobj->parent) - kobject_put(kobj->parent); - kobj->parent = NULL; name = kobj->name; if (kobj->ktype && kobj->ktype->release) kobj->ktype->release(kobj);