Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5198417imm; Tue, 19 Jun 2018 06:44:10 -0700 (PDT) X-Google-Smtp-Source: ADUXVKInjwjPVPrLXUIJAgpxUmVgLzYCoqoipXGBEzkO1PgSpCAcOKU1lniMK+zdzffvZWyZxcYA X-Received: by 2002:a62:138c:: with SMTP id 12-v6mr18404436pft.34.1529415850791; Tue, 19 Jun 2018 06:44:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529415850; cv=none; d=google.com; s=arc-20160816; b=FXjq8MTGoyrAkh0+jNcJtSPCCCNoz0EUkPXSF0IsSstc9AGC0U2ju7ScOg92j2+qny ZsTQuTIqPYZU0bml5XxNn2jfr2EqSDCAmNb1zjtmU5vodzs2yzx0nEQbRp4BNUblehU+ QtNlde0jBE+yVRc2lpJQIDexJshBtzdepOa6lSN58ntaAaufG/bEK1YtDuzdw3czPs2P 39pkb390Z0olYLXDJUt4q7OalZsOL7EbNjtWdf0olo2azDyrAz3TySfOOLrByuk8iQPa uqd8CpsdNQvlnJu+E27cWfaYwmwmGlTYfQSrqaCk6Rkn/Yg3yO2VFX0fIc7yP/kyO6of k8XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=7MCu0WlARFiGW3bIwoW3GrkFHXgknRJy/ZUaMbPhOks=; b=oStVv2px47fLQ9S1pVTEnMY4INq5sEcZQh/po5g/HpwTBDeec7raFbJ2Ou/oWYRCXH PnxbQeHMXk9VU5+Xfy0+PCQ2jMvGG6nNRVQ6/eGLILwzHM0qMWLncdA32NSIO5xbG6p2 TczjRSfTVoR4Nrt+XobgK8mqjXr4Q+5F5OkJR/HVDjF3FePfy+Gq9aI4tj0fQF11TOXn 47zDpIyygwbJyYtnTYzYgaKwOe5cQQMJKtm2d1d37Ek2rZM3KWyp2h7dCBJOtFZVnT3/ sbv+NT2pbVqYCI5S6ksDR/lrBntJJsEQ0WmUmNfmKTpT+ceKszUoka91dL9dOTOkexv/ w5FA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d5-v6si17507568plr.13.2018.06.19.06.43.56; Tue, 19 Jun 2018 06:44:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965731AbeFSNm0 (ORCPT + 99 others); Tue, 19 Jun 2018 09:42:26 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:34647 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S937490AbeFSNmZ (ORCPT ); Tue, 19 Jun 2018 09:42:25 -0400 X-Originating-IP: 208.88.110.46 Received: from localhost (mtl.savoirfairelinux.net [208.88.110.46]) (Authenticated sender: hle@owl.eu.com) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id C00BF6000B; Tue, 19 Jun 2018 13:42:22 +0000 (UTC) Date: Tue, 19 Jun 2018 09:42:20 -0400 From: Hugo Lefeuvre To: Dan Carpenter Cc: Greg Kroah-Hartman , devel@driverdev.osuosl.org, Marcus Wolf , linux-kernel@vger.kernel.org Subject: Re: [PATCH] staging: pi433: fix race condition in pi433_open Message-ID: <20180619134220.GA2396@hle-laptop.local> References: <20180618022400.GA1893@hle-laptop.local> <20180618101838.gzbrxabilnqyilsi@mwanda> <20180619030850.GA1876@hle-laptop.local> <20180619104248.z5nbbakwhjgscufb@mwanda> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="YiEDa0DAkWCtVeE4" Content-Disposition: inline In-Reply-To: <20180619104248.z5nbbakwhjgscufb@mwanda> User-Agent: Mutt/1.10.0 (2018-05-17) X-Spam-Level: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable > > It would be great to get rid of this counter, indeed. But how to do it > > properly without breaking things ? It seems to be useful to me... >=20 > These things are refcounted so you can't unload the module while a file > is open. When we do an open it does a cdev_get(). When we call the > delete_module syscall, it checks the refcount in try_stop_module() -> > try_release_module_ref(). It will still let us force a release but > at that point you're expecting use after frees. Then I'd like to understand why this counter was introduced if remove always gets executed after the last release call returned. This was probably unclear to the original developer. This TODO seems to be related to this misunderstanding too: 890 /* TODO? guard against device removal before, or while, 891 * we issue this ioctl. --> device_get() 892 */ Device removal can't happen before or during the ioctl execution. > > Really ? device->spi is NULL-ed in remove() so that operations on > > remaining fds can detect remove() was already called and free remaining > > resources: > > =20 > > 1296 /* make sure ops on existing fds can abort cleanly */ > > 1297 device->spi =3D NULL; >=20 > That's when we're unloading the module so there aren't any users left. I'll submit an updated version of my patch getting rid of the counter and addressing the remaining race conditions. Thanks ! Regards, Hugo --=20 Hugo Lefeuvre (hle) | www.owl.eu.com 4096/ 9C4F C8BF A4B0 8FC5 48EB 56B8 1962 765B B9A8 BACA --YiEDa0DAkWCtVeE4 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE5LpPtQuYJzvmooL3LVy48vb3khkFAlspCDMACgkQLVy48vb3 khkX6Qf/fTcrcDu8WHvH/VRnCHOKrR9dGSEBruJScyIOKTsHRabTXhZ7FWh1l7VE Sh4BvAGmMC9RvsoliF26D/C/TSSYmfCN0xJvx+ypTReanv9gub12MsaKc/3aq8Qt 7BIvNvUv0S8bDoCaZ4dhvTCswRpndWp6AX53vNHxy1ip1SsV8KFjeyuwtQUmyZ6o Zv3NbldwLthW3p3wSWsXafaGpebi+rZpA9XY9QTWBHyl2TvNl5LgMxrDsjPWrkl5 OD2oZv4JGnDFswvHlx2lOo/7kTODQfNQbrZ9JvTtM4HEfZZcOW8Xw9+4F25+tNU1 p9obTNl2UYcU276eDGcfZXZGtgUQBQ== =UjJb -----END PGP SIGNATURE----- --YiEDa0DAkWCtVeE4--