Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1183869rwd; Thu, 15 Jun 2023 07:23:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42CGNXCacbzsA3hsifNeJinW8iQvsjEon6DsC/xzhR8CDcq1qWy5IXTP4p2+8qDOSlQDWb X-Received: by 2002:a05:6808:1144:b0:398:a09:3cb with SMTP id u4-20020a056808114400b003980a0903cbmr17809060oiu.36.1686838999820; Thu, 15 Jun 2023 07:23:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686838999; cv=none; d=google.com; s=arc-20160816; b=la2UCkniP0OOkXz9ALOl5pk44ICC4f1+b4DOB6/hYJ/khi/J/PywY7mI9dcLJg4u3q DVjCKI0umMyClbrIOunFu+DAJMZAGScFcsdJm9ewvkzcshXFVYGECQSHUYqOwtsRNdqv M4SaNFm7Ig+dIoyV78RbvzjOitlmqDKL+uM1PeQUMl3BwkLM40eWwgq+rk/isMBrjA0O oKzHte3IxoM0ur91hBwf8fg7HPfcakHl/WmNjvsPHobnifuFl2hT5bm65bSEkeVazd5J dAa7FCODEYPuEuqDiU6YM9I1WzV/LZ3D5zdQCb4BMdlAcYljlS3xQfOPWwyrwOZXB4o4 95sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Jhc4fxb+hwuVRLXjtSwH7HnZ1Lqc9d3fsTbjxadvtW4=; b=ZMkVPyWNI3Dici9aZp7d1xbKmzos23wkx6IdLOpajdG1r+rn5uHJBKoGyxBv5uxh4P oNQD0R9nAOIN0+B52X7SPOzoxuHlg11A70X/uxTlV3moSdPfW7nJp+7HNRo3uvB8uuID jXtwWuRCO00mVhtjkzHWJi3oGcee0+7bx6gsyjhLQSiDgBfuz4yJm/huWp82d2W9Mk+8 X/vTtDTWYEOz+8oesQTtUVv1rIuV1k3jch1qSJdnM+QZZfkDfsalRwXAboOc1VVegjRL kYTsdQcIIiqFA0W9sDLFGLwl2UxmDXSWbjzG2ZT4lNJT0YYWzray38b1Ld3SY4Xk7ssi 6aZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KpR36luz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m23-20020a637d57000000b00543ad8bd6dfsi13140006pgn.370.2023.06.15.07.22.47; Thu, 15 Jun 2023 07:23:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KpR36luz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344838AbjFOOGj (ORCPT + 99 others); Thu, 15 Jun 2023 10:06:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344716AbjFOOGh (ORCPT ); Thu, 15 Jun 2023 10:06:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0605B1BE8; Thu, 15 Jun 2023 07:06:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 963D4629A6; Thu, 15 Jun 2023 14:06:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85F76C433C8; Thu, 15 Jun 2023 14:06:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1686837996; bh=2HWxn6SgFtrNnxm9GSS8Rtq52vTNyCTVVqs90CZgSGQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KpR36luzMbFukaoYSxIo/2ySvXZ9EI94ww6JPoZMp9yWn31FB5/1Jc+/1VCbSY/ed xm7JCcRRg7tG5aCgWpZ765U8UWEq/1DZFZF0WW6EFcuYvS4QejYWGHzrK8LmHnV9g1 JMqUL53yXK4Pw9ebkLssTsQF9JW28YovjMw72+0E= Date: Thu, 15 Jun 2023 16:06:33 +0200 From: Greg Kroah-Hartman To: Souradeep Chowdhury Cc: Andy Gross , Konrad Dybcio , Krzysztof Kozlowski , Bjorn Andersson , Rob Herring , Alex Elder , Arnd Bergmann , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, Sibi Sankar , Rajendra Nayak Subject: Re: [PATCH V23 2/3] misc: dcc: Add driver support for Data Capture and Compare unit(DCC) Message-ID: <2023061548-subtly-cackle-8be2@gregkh> References: <2259ab0348282349e88905ea99bcb4aa815d941f.1683265984.git.quic_schowdhu@quicinc.com> <2023061542-reformed-unholy-10a3@gregkh> <2023061515-unbuckled-consonant-e207@gregkh> <5d9ab90f-4fc3-26c6-141e-e9388ac2f0cf@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5d9ab90f-4fc3-26c6-141e-e9388ac2f0cf@quicinc.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 15, 2023 at 07:17:34PM +0530, Souradeep Chowdhury wrote: > > > > > +static ssize_t ready_read(struct file *filp, char __user *userbuf, > > > > > + size_t count, loff_t *ppos) > > > > > +{ > > > > > + int ret = 0; > > > > > + char *buf; > > > > > + struct dcc_drvdata *drvdata = filp->private_data; > > > > > + > > > > > + mutex_lock(&drvdata->mutex); > > > > > + > > > > > + if (!is_dcc_enabled(drvdata)) { > > > > > + ret = -EINVAL; > > > > > + goto out_unlock; > > > > > + } > > > > > + > > > > > + if (!FIELD_GET(BIT(1), readl(drvdata->base + dcc_status(drvdata->mem_map_ver)))) > > > > > + buf = "Y\n"; > > > > > + else > > > > > + buf = "N\n"; > > > > > +out_unlock: > > > > > + mutex_unlock(&drvdata->mutex); > > > > > + > > > > > + if (ret < 0) > > > > > + return -EINVAL; > > > > > + else > > > > > > > > You do the "lock, get a value, unlock, do something with the value" > > > > thing a bunch, but what prevents the value from changing after the lock > > > > happens? So why is the lock needed at all? > > > > > > The lock is used to prevent concurrent accesses of the drv_data when > > > scripts are being run from userspace. > > > > How would that matter? The state can change instantly after the lock is > > given up, and then the returned value is now incorrect. So no need for > > a lock at all as you really aren't "protecting" anything, or am I > > missing something else? > > This lock is needed to protect the access to the global instance of drv_data > structure instantiated at probe time within each individual callbacks of > debugfs. What exactly are you "protecting" here that could change in a way that cause a problem? You aren't returning a value that is ever guaranteed to be "correct" except that it happened sometime in the past, it might be right anymore. thanks, greg k-h