From owner-svn-src-all@FreeBSD.ORG Mon Aug 13 21:01:07 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6FD9A1065678; Mon, 13 Aug 2012 21:01:07 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id 3FC5C8FC15; Mon, 13 Aug 2012 21:01:07 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id C7579B94B; Mon, 13 Aug 2012 17:01:05 -0400 (EDT) From: John Baldwin To: Hans Petter Selasky Date: Mon, 13 Aug 2012 17:00:25 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p17; KDE/4.5.5; amd64; ; ) References: <201208101502.q7AF2ofC046316@svn.freebsd.org> <201208130949.07399.jhb@freebsd.org> <201208132143.42298.hselasky@c2i.net> In-Reply-To: <201208132143.42298.hselasky@c2i.net> MIME-Version: 1.0 Content-Type: Text/Plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Message-Id: <201208131700.25822.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Mon, 13 Aug 2012 17:01:05 -0400 (EDT) Cc: "svn-src-head@freebsd.org" , "svn-src-all@freebsd.org" , "src-committers@freebsd.org" Subject: Re: svn commit: r239178 - in head/sys: kern sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Mon, 13 Aug 2012 21:01:07 -0000 On Monday, August 13, 2012 3:43:42 pm Hans Petter Selasky wrote: > On Monday 13 August 2012 15:49:07 John Baldwin wrote: > > On Friday, August 10, 2012 11:02:50 am Hans Petter Selasky wrote: > > > Author: hselasky > > > Date: Fri Aug 10 15:02:49 2012 > > > New Revision: 239178 > > > URL: http://svn.freebsd.org/changeset/base/239178 > > > > > > Log: > > > Add new device method to free the automatically > > > allocated softc structure which is returned by > > > device_get_softc(). This method can be used to > > > easily implement softc refcounting. This can be > > > desirable when the softc has memory references > > > which are controlled by userspace handles for > > > example. > > > > Why do you need a new method? If you want to manage your own softc, you > > are free to do so by using a size of 0 in your driver_t. You can then use > > device_set_softc() to set the softc during your attach routine. New-bus > > won't free it during detach leaving you to free it instead. That is what > > you should have done here instead of polluting device_if.m. Note that > > DF_EXTERNALSOFTC is an internal flag to explicitly handle this case, but > > you've now made it possible for a device to try to do special free logic > > but haven't made DF_EXTERNALSOFTC visible to that driver. This is why I > > think new-bus already let you do what you wanted (via device_set_softc()) > > and think you should just do that and back this out. > > Hi, > > I know that drivers can manage their own softc's, only that it will add 5-10 > more lines of code and error handling to each UCOM client driver, instead of > using the .size field which factors all of this out of the driver. I don't think you need 5-10 lines, more like 1 or 2. This: struct driver_t { ... sizeof(struct foo_softc) }; int foo_attach(device_t dev) { struct foo_softc *sc; sc = device_get_softc(dev); ... } becomes: struct driver_t { ... 0 }; int foo_attach(device_t dev) { struct foo_softc *sc; sc = malloc(sizeof(struct foo_softc), M_BUS, M_WAITOK | M_ZERO); device_set_softc(dev, sc); ... } -- John Baldwin