Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp693368ybt; Wed, 24 Jun 2020 08:58:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzr4blEuTYgy90ZXjuE3CtfJsWX8sSsEYCXCwr1+mPEKdYk5b8UEGIfVkxbyF8sOiFnF1sf X-Received: by 2002:a17:906:c672:: with SMTP id ew18mr26702840ejb.404.1593014325901; Wed, 24 Jun 2020 08:58:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593014325; cv=none; d=google.com; s=arc-20160816; b=zTcw1lS+GY3kYU1Ygh5Z4PyJLlF6+4O1iNxLm9XGl0hJ9Lw9HibjgbJCETORKfufWK joTHLB1IyQdQWZC1erj2f2Y9cRZxzPMgGaaGN01pTgSz6l9yZpYJRZzJn3LnrDPyWIfJ Hb4QFb5KJIZblL26Lr9pmf4ol6slgvI6H39EDGqGl9CpXCy4vqqE8wBDp8L07yPb2euz ViFuXnDUZ0zC1NJwKPLXG1yplyPP/g6Dn6CdA79J54CXmtBc+kx7UEXKbHx/3SEwMuu7 o2mKgVEuy1lZntrvp+/ZFNQdWOmdMTessdWjV4/gxvFNn6Sn9r2QCe92xuk6Ne/MhiHX YTcQ== 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:dkim-signature; bh=Ptn2w5e6anRr1NlNku10i3q3CyuFAMfWr3pdlWZGFp4=; b=F58OXhm49K7k2tgnbfjTXQv6KcJOoqNc2DBwMtpFNasOq8khf4cWkDhKPLjUOMkCn0 XLmPLleW7lYGYdz7460zzb9PV+h4FnloCsu4DllpKs5XmldN/5XWSoZTt1pXIv7TC63C SPg2NEIT0/C89LccyJxlMDGZhdAe+0VKE11ayg0JbvJPSQ5+Z6idC6qoNiE/Eu4w/u6A uCSAsIIO6ksN3RDW+g5eD1jpcjgQ1bo4Y8lSACGfG9ZggdcfUgFTuPzuMFvrh3fANXzn wczermUfZ37vjZxNBCkSqBsEYeVvTaCb1Md2Tx9oQjZ8xEQ8F9Blc0peyvR8u8YV2CYW Mw4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IbAR3hxG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n7si13248971edt.65.2020.06.24.08.58.21; Wed, 24 Jun 2020 08:58:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IbAR3hxG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404764AbgFXP50 (ORCPT + 99 others); Wed, 24 Jun 2020 11:57:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404751AbgFXP5V (ORCPT ); Wed, 24 Jun 2020 11:57:21 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BB92C061573; Wed, 24 Jun 2020 08:57:21 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id g17so1203184plq.12; Wed, 24 Jun 2020 08:57:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Ptn2w5e6anRr1NlNku10i3q3CyuFAMfWr3pdlWZGFp4=; b=IbAR3hxGsMrhz5UYf7u/9VpJa12J4CTZ1s9fwmcXSWa0Q6L6+pu22ca03mkDFu49/g AZ2/Xe114B9qUmNQDYqo4yo/4LSBw/u/cY0nap9cgwy3p5NTBRUzPg6k2HKoUfGJ44o7 ScnG5V6Gm1l5wDr8Hx9R/YAvlmszfqo7yHBhMJDKQhouMPIH8ZciRX5RJkKEs5RtbOYY 8rHA+ejnuGXfMqZKCChz83nPmQCidGEXC04y4EOzxG6O2S0ctult5PC0GuZvHv0o51HW z+tVpIZcdSUq0J95eYVYbn+DL+ZXViXu38qV5FxtSoUgO4L3QIfRKii8qPOlC3B0s+LW Jp1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Ptn2w5e6anRr1NlNku10i3q3CyuFAMfWr3pdlWZGFp4=; b=IgqxkHC3Hqxw42pi2g+vBMVlmNJvWiCaWKiThRQRwob0q9ll5UUHykaF7C6jQ5judA NHpfAioX5RyAmkIOgPoB5KthyIsLT7AGg+KmGcRMqFbtw5d8Nu9cDH9tsIfdl4JAwq2e eVHoEbcNjS4QhV6Su887A+DchTB2nHOXO/RqngtfuZzRKjGc8ZrVN4AAbPvH/ItBm9Cv D88ZECMb2UXOMVoowCVss9K3ZI0AfJTPhi2bBWk8ikoACIQkUDqSWQCeVVXUy25wCuM9 vPJ66nAAdvJfkiDm8aggC1E5m+Zp2D1IWnOdQ8o7ZAg2y2/EL7cOxSGd+XlqsL31XtmV 6pFA== X-Gm-Message-State: AOAM532eUXlNBR2gX5i6wXsoTOmiKG2KqQOJnrCrWa1QDLJG0XTsaQMR A7V3ykYD+w6WTOy4Tv/sJNrZ+J6XYEBc6Q== X-Received: by 2002:a17:90a:d709:: with SMTP id y9mr6546265pju.30.1593014240728; Wed, 24 Jun 2020 08:57:20 -0700 (PDT) Received: from sol (220-235-99-174.dyn.iinet.net.au. [220.235.99.174]) by smtp.gmail.com with ESMTPSA id h8sm17082362pgm.16.2020.06.24.08.57.17 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jun 2020 08:57:19 -0700 (PDT) Date: Wed, 24 Jun 2020 23:57:14 +0800 From: Kent Gibson To: Andy Shevchenko Cc: Linux Kernel Mailing List , "open list:GPIO SUBSYSTEM" , Bartosz Golaszewski , Linus Walleij Subject: Re: [PATCH 10/22] gpiolib: cdev: fix minor race in GET_LINEINFO_WATCH Message-ID: <20200624155714.GB8622@sol> References: <20200623040107.22270-1-warthog618@gmail.com> <20200623040107.22270-11-warthog618@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 24, 2020 at 05:46:33PM +0300, Andy Shevchenko wrote: > On Tue, Jun 23, 2020 at 7:03 AM Kent Gibson wrote: > > > > Merge separate usage of test_bit/set_bit into test_and_set_bit to remove > > the possibility of a race between the test and set. > > > > Similarly test_bit and clear_bit. > > > > In the existing code it is possible for two threads to race past the > > test_bit and then set or clear the watch bit, and neither return EBUSY. > > I stumbled over this myself, but... > > > - if (test_bit(hwgpio, gcdev->watched_lines)) > > + if (test_and_set_bit(hwgpio, gcdev->watched_lines)) > > return -EBUSY; > > > > gpio_desc_to_lineinfo(desc, &lineinfo); > > @@ -897,7 +897,6 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) > > if (copy_to_user(ip, &lineinfo, sizeof(lineinfo))) > > return -EFAULT; > > > > - set_bit(hwgpio, gcdev->watched_lines); > > return 0; > > ...I think it's not an equivalent despite races involved. If you set > bit and return error code, you will have the wrong state. > Not quite sure what you mean. There is only an error if the bit is already set, so you've changed nothing. And the watched state is not part of the lineinfo, so the state returned is the same either way. Cheers, Kent.