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 0C4B9C433EF for ; Fri, 6 May 2022 03:39:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234539AbiEFDmk (ORCPT ); Thu, 5 May 2022 23:42:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388762AbiEFDmg (ORCPT ); Thu, 5 May 2022 23:42:36 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67EA1B3C; Thu, 5 May 2022 20:38:55 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id iq2-20020a17090afb4200b001d93cf33ae9so9711570pjb.5; Thu, 05 May 2022 20:38:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Thh8y0B9U/Ip36Z1pHukPlR3kRPTnswuR34K+vKB1hc=; b=jsSM5j5/VLW8HThEJQ93pP3WnLRDj8yZPD+jNB+uxemWTHylJixdD/TP2lI1S55jZy KyB5sUKuBuNGn+2pyep9IjJX7VbnCLCVyR7UaUWiS+zKLAoms9MX+fECPaMmuANKm3Jo rUkXmDyDBPG7addk/1Jd38sw3uKMAXnu2x3kTCFpunj8Nm92etBwD7TmsZhPp4R535oL koYWD3EHcMX6efoKpmiZleep8nO5AWFeWCpkTesK07bW5CIecpNf8RfqmnThB+eXT1su lfIIx4/ljqVoozDaIwYSA8QFGWqrI1wf25CJQLP6s9hIslttbGdAYDL5Tnub6v7jVYXW fz6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Thh8y0B9U/Ip36Z1pHukPlR3kRPTnswuR34K+vKB1hc=; b=23NJWDVc4IygW6mQZXrPbrj8zq16Ppo1zJacVXTh8nM6hHQDBansInFCpb2AUjF8AP VcP2xta5nZm235e0blTb02/FzfUXZ1cc6rrrG67Stykl2vO/sIJu0ikKbQKWmWTp2iNF V+IGV2gHNfebeEt0pqk1NRy5AiOm8FWmNl1kG7V0RLH31mgtcpK9diUBo7R23bhpNr9l jQ6eSkSKMyeGA0LsILqXpCaMpCg5QvmrLwrJv8P/N+IYNSDMenEqhap+A0zuFNKiJPZ/ kPtFLzyXLOmlHeCrtMdM2CJgqZNBtwDqlfyW/CscO3STnaUnLX2SSHH9NRU8nyGa/k2r C9zQ== X-Gm-Message-State: AOAM531KcksQzF7wt0DcJszmveLMok/0bPCZo1A6TXSC7Uv7gOGUeza4 BrHdntbctytFsnxnTnxCfoA= X-Google-Smtp-Source: ABdhPJxD8Oz0oOTM/oDFE5euDEomfuAH3/F7pvBij12hDEABwIFX21X+VhyiYg8cC1T2dVdGBBo7qQ== X-Received: by 2002:a17:902:f684:b0:15e:8c4a:c54b with SMTP id l4-20020a170902f68400b0015e8c4ac54bmr1433588plg.21.1651808334809; Thu, 05 May 2022 20:38:54 -0700 (PDT) Received: from sol ([118.209.204.33]) by smtp.gmail.com with ESMTPSA id t7-20020a170902e84700b0015e8d4eb242sm412700plg.140.2022.05.05.20.38.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 20:38:54 -0700 (PDT) Date: Fri, 6 May 2022 11:38:49 +0800 From: Kent Gibson To: Bartosz Golaszewski Cc: Yihao Han , Linus Walleij , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List Subject: Re: [PATCH] gpiolib: cdev: fix stream_open.cocci warnings Message-ID: <20220506033849.GA12555@sol> References: <20220505115011.3435-1-hanyihao@vivo.com> <20220505122450.GA23659@sol> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220505122450.GA23659@sol> Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org On Thu, May 05, 2022 at 08:24:50PM +0800, Kent Gibson wrote: > On Thu, May 05, 2022 at 02:18:48PM +0200, Bartosz Golaszewski wrote: > > On Thu, May 5, 2022 at 1:50 PM Yihao Han wrote: > > > > > > ./drivers/gpio/gpiolib-cdev.c:2498:7-23: WARNING: > > > gpio_fileops: .read() has stream semantic; > > > safe to change nonseekable_open -> stream_open. > > > > > > Generated by: scripts/coccinelle/api/stream_open.cocci > > > > > > Signed-off-by: Yihao Han > > > --- > > > drivers/gpio/gpiolib-cdev.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c > > > index f5aa5f93342a..d03c8e012c8c 100644 > > > --- a/drivers/gpio/gpiolib-cdev.c > > > +++ b/drivers/gpio/gpiolib-cdev.c > > > @@ -2495,7 +2495,7 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file) > > > get_device(&gdev->dev); > > > file->private_data = cdev; > > > > > > - ret = nonseekable_open(inode, file); > > > + ret = stream_open(inode, file); > > > if (ret) > > > goto out_unregister_notifier; > > > > > > -- > > > 2.17.1 > > > > > > > Cc'ing Kent. > > > > This patch doesn't seem to target current master or rc1. > > > > It also can't be right - we specifically mark all filesystem objects > > exposed by the GPIO character device as non-seekable. > > > > Agreed. I took the coccinelle warning as being a false positive. > If I recall correctly I had a quick look to see if it could be disabled, > but didn't find anything, and so just ignored it. > Further to this... The coccinelle warning says: // Search for stream-like files that are using nonseekable_open and convert // them to stream_open. A stream-like file is a file that does not use ppos in // its read and write. Rationale for the conversion is to avoid deadlock in // between read and write. The rationale is not applicable here, as all cdev files are non-writeable, as well as being non-seekable. But switching to stream_open(), as coccinelle suggests, is probably fine. The doco for stream_open() says: * stream_open is used by subsystems that want stream-like file descriptors. * Such file descriptors are not seekable and don't have notion of position * (file.f_pos is always 0 and ppos passed to .read()/.write() is always NULL). * Contrary to file descriptors of other regular files, .read() and .write() * can run simultaneously. so it would also produce nonseekable files. Comparing nonseekable_open() with stream_open(), the latter clears FMODE_ATOMIC_POS and sets FMODE_STREAM, neither of which are relevant for the cdev use cases, so that should be ok. So I would be ok with the patch if it were updated to apply to the current gpiolib-cdev.c. Cheers, Kent.