From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Reding Subject: Re: [PATCH 06/13] drm: add minor-lookup/release helpers Date: Fri, 21 Feb 2014 08:37:33 +0100 Message-ID: <20140221073732.GF22574@ulmo.nvidia.com> References: <1391004120-687-1-git-send-email-dh.herrmann@gmail.com> <1391004120-687-7-git-send-email-dh.herrmann@gmail.com> <20140221070910.GB22574@ulmo.nvidia.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0293130494==" Return-path: Received: from mail-bk0-f41.google.com (mail-bk0-f41.google.com [209.85.214.41]) by gabe.freedesktop.org (Postfix) with ESMTP id D626BFB363 for ; Thu, 20 Feb 2014 23:37:36 -0800 (PST) Received: by mail-bk0-f41.google.com with SMTP id na10so954579bkb.28 for ; Thu, 20 Feb 2014 23:37:35 -0800 (PST) In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org To: David Herrmann Cc: Daniel Vetter , "dri-devel@lists.freedesktop.org" List-Id: dri-devel@lists.freedesktop.org --===============0293130494== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="pyE8wggRBhVBcj8z" Content-Disposition: inline --pyE8wggRBhVBcj8z Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 21, 2014 at 08:34:15AM +0100, David Herrmann wrote: > Hi >=20 > On Fri, Feb 21, 2014 at 8:09 AM, Thierry Reding > wrote: > > On Wed, Jan 29, 2014 at 03:01:53PM +0100, David Herrmann wrote: > > [...] > >> diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c > >> index c51333e..d3232b6 100644 > >> --- a/drivers/gpu/drm/drm_stub.c > >> +++ b/drivers/gpu/drm/drm_stub.c > >> @@ -356,6 +356,45 @@ static void drm_unplug_minor(struct drm_minor *mi= nor) > >> } > >> > >> /** > >> + * drm_minor_acquire - Acquire a DRM minor > >> + * @minor_id: Minor ID of the DRM-minor > >> + * > >> + * Looks up the given minor-ID and returns the respective DRM-minor o= bject. The > >> + * refence-count of the underlying device is increased so you must re= lease this > >> + * object with drm_minor_release(). > >> + * > >> + * As long as you hold this minor, it is guaranteed that the object a= nd the > >> + * minor->dev pointer will stay valid! However, the device may get un= plugged and > >> + * unregistered while you hold the minor. > >> + * > >> + * Returns: > >> + * Pointer to minor-object with increased device-refcount, or PTR_ERR= on > >> + * failure. > >> + */ > >> +struct drm_minor *drm_minor_acquire(unsigned int minor_id) > >> +{ > >> + struct drm_minor *minor; > >> + > >> + minor =3D idr_find(&drm_minors_idr, minor_id); > >> + if (!minor) > >> + return ERR_PTR(-ENODEV); > >> + > >> + drm_dev_ref(minor->dev); > > > > Is it possible that somebody would drop the last reference on the device > > right between the idr_find() call and drm_dev_ref()? In which case both > > the device and the minor will have become invalid when drm_dev_ref() is > > called. >=20 > No, it's locked via the drm_global_mutex. And later I introduce a > spinlock here that protects this in case we remove the global lock. Indeed. Thanks for clarifying. Thierry --pyE8wggRBhVBcj8z Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBAgAGBQJTBwI8AAoJEN0jrNd/PrOhyOQP/1EfIAlRBofkJgiAT03A8kNt DWiKGNmGtrkXS3Hnq7j05CqJhsGgvs9xxp0f4ZAThofpJC2C8OhRlPaUyad/a8uW PrJSfe8+u/pyGCgJPtUB6wjwQMaBbuWvtNtqah1DiEgofh1ios1OVFxuyRbGnBAX /LpY6sXL7mGouejOfa44QCjolfBkfmIsVrNjYM0X+wik2PduQptyRk+2r08Eztcr 8GcwcYU02Ks4O8T50xtuGe8vaJoaw/mRVhx67uxc/O8z7UmINepWVlkMDaHYHsPt shB3YwfzpBgIXQGGzdXyRLAqRs/NYGnyVdpWT81WNuZ/u6fmySUQrcO/6rZxqx+1 592NE4YeDjlhMLdtqtr/HyG8KzSwyKMhiM+mm1kig9loMu37r0tbmV2BfGadlvX+ nfU20Z8iZACszJ6wyZHGmM4bKm01REBOwSCJne25qEUoDdl8UWug6fQ/4A8R65Qy zqUlMXpT0JuPu8CndFSyT/UBKd7QeHy3oQl4ilDhnlYvb2fuspDXW0fB46mVOd8s k4fJJhhhRVE9IlihXXLBPgc4aWL+BXqEFGdS8+Nf4pQdszN3dDSpPJAELuGBs58L WUXzr0Q+sCOOt9Wz5Eo9UBKSnbz8eZxWPYUAbAeGjNeGf4ITEfozloXsUZeHdKLA ULMQw5DHPg9MyUXdbRTw =7B8I -----END PGP SIGNATURE----- --pyE8wggRBhVBcj8z-- --===============0293130494== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/dri-devel --===============0293130494==--