devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Souradeep Chowdhury <quic_schowdhu@quicinc.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Andy Gross <agross@kernel.org>,
	Konrad Dybcio <konrad.dybcio@somainline.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Rob Herring <robh+dt@kernel.org>, Alex Elder <elder@ieee.org>,
	Arnd Bergmann <arnd@arndb.de>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <linux-arm-msm@vger.kernel.org>,
	<devicetree@vger.kernel.org>,
	Sibi Sankar <quic_sibis@quicinc.com>,
	"Rajendra Nayak" <quic_rjendra@quicinc.com>
Subject: Re: [PATCH V23 2/3] misc: dcc: Add driver support for Data Capture and Compare unit(DCC)
Date: Wed, 21 Jun 2023 14:48:23 +0530	[thread overview]
Message-ID: <31cb09ae-dbb8-8ba0-08dc-fcc2af63ca30@quicinc.com> (raw)
In-Reply-To: <2023061548-subtly-cackle-8be2@gregkh>



On 6/15/2023 7:36 PM, Greg Kroah-Hartman wrote:
> 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.

Hi Greg,

The lock doesn't add any value in this particular case and I will be 
dropping it from here but in other cases it is being used to protect the 
concurrent access of the data-structures used inside the drv_data mainly 
the list which is being used to append register configurations, write 
the configuration to the dcc_sram and also delete it while doing a 
config reset. The lock is also used in case of software trigger to read 
the bitmap of the lists to set register values.

Thanks,
Souradeep

> 
> thanks,
> 
> greg k-h

  reply	other threads:[~2023-06-21  9:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-05  6:36 [PATCH V23 0/3] misc: Add driver support for Data Capture and Compare unit(DCC) Souradeep Chowdhury
2023-05-05  6:36 ` [PATCH V23 1/3] dt-bindings: misc: qcom,dcc: Add the dtschema Souradeep Chowdhury
2023-05-05  6:36 ` [PATCH V23 2/3] misc: dcc: Add driver support for Data Capture and Compare unit(DCC) Souradeep Chowdhury
2023-05-24  5:10   ` Trilok Soni
2023-05-31 16:17     ` Trilok Soni
2023-06-15 10:33   ` Greg Kroah-Hartman
2023-06-15 12:43     ` Souradeep Chowdhury
2023-06-15 12:50       ` Greg Kroah-Hartman
2023-06-15 13:47         ` Souradeep Chowdhury
2023-06-15 14:06           ` Greg Kroah-Hartman
2023-06-21  9:18             ` Souradeep Chowdhury [this message]
2023-05-05  6:36 ` [PATCH V23 3/3] MAINTAINERS: Add the entry for DCC(Data Capture and Compare) driver support Souradeep Chowdhury
2023-05-24  4:55 ` [PATCH V23 0/3] misc: Add driver support for Data Capture and Compare unit(DCC) Souradeep Chowdhury
2023-06-07  5:26 ` Souradeep Chowdhury
2023-06-15 10:26 ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=31cb09ae-dbb8-8ba0-08dc-fcc2af63ca30@quicinc.com \
    --to=quic_schowdhu@quicinc.com \
    --cc=agross@kernel.org \
    --cc=andersson@kernel.org \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=elder@ieee.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=konrad.dybcio@somainline.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quic_rjendra@quicinc.com \
    --cc=quic_sibis@quicinc.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).