From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC58CC4332F for ; Wed, 30 Nov 2022 12:32:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234847AbiK3Mb6 (ORCPT ); Wed, 30 Nov 2022 07:31:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229974AbiK3Mby (ORCPT ); Wed, 30 Nov 2022 07:31:54 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1D7A4A59C; Wed, 30 Nov 2022 04:31:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669811512; x=1701347512; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=zKETJrfvjw63GEKgdDVGoEq/Ye/042EOL11iLLnZW9M=; b=j/x5TX+HSBvF+8SD3czI6tiMUss7Q+ue0CLhb0Ap0yld6WBlcnPcKUw0 UeJAA4V8ry90yTdRHyOBmuo+jfD6IeB4Ly1d1hu530lAjhjSy8zIpIVmq nrmfU3orWV2H7r36e/w0LXNUVK1NeQlnNH9HyLimNLXw2X4Pb9VnxZymn wUrC6AGb6AKpPyvjJ5s12D4iWEUWu/2jS+M5KtUGyox1E8CP2yJBk0JO5 tatOEY+gIDPRq3cfgJVDkwbE063wvCSm64PMWv5oG5c+Wngtvv1gUSXrD UcYAzPIhfJeGepyQaqw01Z0LGDTmEZX+HNEnyHym3I7zoGpQWut2Axp7G A==; X-IronPort-AV: E=McAfee;i="6500,9779,10546"; a="295079868" X-IronPort-AV: E=Sophos;i="5.96,206,1665471600"; d="scan'208";a="295079868" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2022 04:31:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10546"; a="644197486" X-IronPort-AV: E=Sophos;i="5.96,206,1665471600"; d="scan'208";a="644197486" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga002.jf.intel.com with ESMTP; 30 Nov 2022 04:31:50 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1p0MFg-002G4C-2p; Wed, 30 Nov 2022 14:31:48 +0200 Date: Wed, 30 Nov 2022 14:31:48 +0200 From: Andy Shevchenko To: Bartosz Golaszewski Cc: Kent Gibson , Linus Walleij , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: Re: [PATCH v4 2/2] gpiolib: protect the GPIO device against being dropped while in use by user-space Message-ID: References: <20221130090556.40280-1-brgl@bgdev.pl> <20221130090556.40280-3-brgl@bgdev.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 30, 2022 at 01:05:30PM +0100, Bartosz Golaszewski wrote: > On Wed, Nov 30, 2022 at 1:02 PM Andy Shevchenko > wrote: > > On Wed, Nov 30, 2022 at 10:05:56AM +0100, Bartosz Golaszewski wrote: > > > + down_read(&gdev->sem); > > > > Thinking more about this, wouldn't be better to actually > > > > ret = down_read_trylock(&gdev->sem); > > if (ret) > > return ret; > > > > ? > > You mean as in: try to take the lock, but if we're already removing > the device (as the down_write() can only happen in gpiochip_remove()), > then die right away? Smart! Yeah, I'll do it this way. But please check return values properly (it seems not obvious what it does return). -- With Best Regards, Andy Shevchenko