From owner-freebsd-current@FreeBSD.ORG Sat Apr 17 22:06:24 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5D2C916A4CE for ; Sat, 17 Apr 2004 22:06:24 -0700 (PDT) Received: from root.org (root.org [67.118.192.226]) by mx1.FreeBSD.org (Postfix) with SMTP id 20FCE43D39 for ; Sat, 17 Apr 2004 22:06:24 -0700 (PDT) (envelope-from nate@root.org) Received: (qmail 10463 invoked by uid 1000); 18 Apr 2004 05:06:26 -0000 Date: Sat, 17 Apr 2004 22:06:26 -0700 (PDT) From: Nate Lawson To: current@freebsd.org Message-ID: <20040417220208.D10434@root.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: refcounting for devclass_get_devices() X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 Apr 2004 05:06:24 -0000 I am doing some locking work and ran across a tough case. It's useful to use devclass_get_devices() when iterating across a whole set of softcs. However, I didn't want to implement my own refcount for the returned pointer. Are there any plans to deal with this interface? As a driver, how can I know when a device is going away or keep it refed because I hold a pointer to its softc? Since it mallocs data, I can't hold a device lock across calling it and by the next instruction, one of the devices in the array may have been destroyed. The code is usually: devclass_get_devices(acpi_cmbat_devclass, &acpi_cmbat_devs, &acpi_cmbat_units); for (i = 0; i < acpi_cmbat_units; i++) sc = device_get_softc(acpi_cmbat_devs[i]); ... Thanks, Nate