linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "weiyongjun (A)" <weiyongjun1@huawei.com>
To: Frank Rowand <frowand.list@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>, Rob Herring <robh+dt@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <linux-spi@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>
Subject: Re: [PATCH -next 3/4] spi: mockup: Add runtime device tree overlay interface
Date: Tue, 30 Aug 2022 11:05:44 +0800	[thread overview]
Message-ID: <4eab3d1a-199f-fdfe-8d8f-3369eeefde47@huawei.com> (raw)
In-Reply-To: <8c436553-e35c-4e46-1407-24184fd113ba@gmail.com>



On 2022/8/30 5:29, Frank Rowand wrote:
> comment inline below, plus adding to cc: and to: list
> 
> On 8/26/22 09:43, Wei Yongjun wrote:
>> Add a runtime device tree overlay interface for device need dts file.
>> With it its possible to use device tree overlays without having to use
>> a per-platform overlay manager.
> 
> Why is an overlay needed?  The documentation in patch 4 shows providing
> a dtb as an argument to the qemu-system-x86_64 command, which should be
> sufficient to supply the appropriate dtb.

Fist, we are aimed to build a device driver regression testsuit. Without
overlay, lots of the dtb fragments must be combined to a very big one, it
may different to maintainence. overlay makes easily to attach/detech as
the device's requirement.

Seconds, overlay dts may be used to found or verification issues related
to of_node_put or others, such as patches like:

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/?qt=grep&q=node_put

many of them may found by static check tool, which may leak of tesing.

The documentation I post does not use overlay dts, but when overlay
dts[1] is used, we can found the of node leak:

$ python3 -m kddv.cmds.mock -b spi -d mchp23k256
create spi device mchp23k256 success!
$ ls /sys/bus/spi/drivers/mchp23k256/spi0.0/mtd/
mtd0  mtd0ro
$ python3 -m kddv.cmds.mock -b spi -d mchp23k256 -r
[  233.508565] Deleting MTD partitions on "spi0.0":
[  233.516784] OF: ERROR: memory leak, expected refcount 1 instead of 2,
  of_node_get()/of_node_put() unbalanced - destroy cset entry: attach
  overlay node /spi/spi-sram@0
remove spi device mchp23k256 success!

Not sure it is worth to fix issues like this, but at least, we can
tesing them now.

-[1]---------------------------------------------------------
/dts-v1/;
/plugin/;

&{/spi} {
	spi-sram@0 {
		#address-cells = <1>;
		#size-cells = <1>;
		compatible = "microchip,mchp23k256";
		reg = <0>;
		spi-max-frequency = <20000000>;
	};
};

-------------------------------------------------------

Regards,
Wei Yongjun

> 
> -Frank
> 
>>
>> Add a new device by command:
>> $ cat test.dtbo > /sys/class/spi_master/spi0/overlay_fdto
>>
>> Remove the device by command:
>> $ echo remove > /sys/class/spi_master/spi0/overlay_fdto
>>
>> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
>> ---
>>   drivers/spi/Kconfig      |  2 ++
>>   drivers/spi/spi-mockup.c | 48 ++++++++++++++++++++++++++++++++++++++++
>>   2 files changed, 50 insertions(+)
>>
>> diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
>> index e0f0fa2746ad..4b7c84ddb367 100644
>> --- a/drivers/spi/Kconfig
>> +++ b/drivers/spi/Kconfig
>> @@ -1161,6 +1161,8 @@ config SPI_TLE62X0
>>   config SPI_MOCKUP
>>   	tristate "SPI controller Testing Driver"
>>   	depends on OF
>> +	select OF_EARLY_FLATTREE
>> +	select OF_RESOLVE
>>   	select BPF_EVENTS
>>   	help
>>   	  This enables SPI controller testing driver, which provides a way to
>> diff --git a/drivers/spi/spi-mockup.c b/drivers/spi/spi-mockup.c
>> index 7a93b194ee53..404ad821bf6a 100644
>> --- a/drivers/spi/spi-mockup.c
>> +++ b/drivers/spi/spi-mockup.c
>> @@ -21,6 +21,9 @@
>>   struct mockup_spi {
>>   	struct mutex lock;
>>   	struct spi_device *devs[MOCKUP_CHIPSELECT_MAX];
>> +
>> +	void *fdto;
>> +	int ovcs_id;
>>   };
>>   
>>   static struct spi_master *to_spi_master(struct device *dev)
>> @@ -145,9 +148,53 @@ delete_device_store(struct device *dev, struct device_attribute *attr,
>>   }
>>   static DEVICE_ATTR_WO(delete_device);
>>   
>> +static ssize_t
>> +overlay_fdto_store(struct device *dev, struct device_attribute *attr,
>> +		   const char *buf, size_t count)
>> +{
>> +	struct spi_master *master = to_spi_master(dev);
>> +	struct mockup_spi *mock = spi_master_get_devdata(master);
>> +	int ret;
>> +
>> +	mutex_lock(&mock->lock);
>> +
>> +	if (strncmp(buf, "remove\n", count) == 0) {
>> +		if (mock->ovcs_id < 0) {
>> +			ret = -ENOENT;
>> +			goto out_unlock;
>> +		}
>> +		of_overlay_remove(&mock->ovcs_id);
>> +		kfree(mock->fdto);
>> +		mock->ovcs_id = -1;
>> +		mock->fdto = NULL;
>> +	} else {
>> +		if (mock->ovcs_id >= 0) {
>> +			ret = -EINVAL;
>> +			goto out_unlock;
>> +		}
>> +		mock->fdto = kmemdup(buf, count, GFP_KERNEL);
>> +		if (!mock->fdto) {
>> +			ret = -ENOMEM;
>> +			goto out_unlock;
>> +		}
>> +		ret = of_overlay_fdt_apply(mock->fdto, count, &mock->ovcs_id);
>> +		if (ret < 0)
>> +			goto out_unlock;
>> +	}
>> +
>> +	mutex_unlock(&mock->lock);
>> +	return count;
>> +
>> +out_unlock:
>> +	mutex_unlock(&mock->lock);
>> +	return ret;
>> +}
>> +static DEVICE_ATTR_WO(overlay_fdto);
>> +
>>   static struct attribute *spi_mockup_attrs[] = {
>>   	&dev_attr_new_device.attr,
>>   	&dev_attr_delete_device.attr,
>> +	&dev_attr_overlay_fdto.attr,
>>   	NULL
>>   };
>>   ATTRIBUTE_GROUPS(spi_mockup);
>> @@ -227,6 +274,7 @@ static int spi_mockup_probe(struct platform_device *pdev)
>>   
>>   	mock = spi_master_get_devdata(master);
>>   	mutex_init(&mock->lock);
>> +	mock->ovcs_id = -1;
>>   
>>   	ret = spi_register_master(master);
>>   	if (ret) {
> 

  reply	other threads:[~2022-08-30  3:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-26 14:43 [PATCH -next 0/4] spi: Introduce BPF based SPI mockup controller Wei Yongjun
2022-08-26 14:43 ` [PATCH -next 1/4] spi: mockup: Add SPI controller testing driver Wei Yongjun
2022-08-30 19:11   ` Mark Brown
2022-08-31  4:39     ` weiyongjun (A)
2022-08-26 14:43 ` [PATCH -next 2/4] spi: mockup: Add writeable tracepoint for spi transfer Wei Yongjun
2022-08-30 18:14   ` Mark Brown
2022-08-31  4:43     ` weiyongjun (A)
2022-08-26 14:43 ` [PATCH -next 3/4] spi: mockup: Add runtime device tree overlay interface Wei Yongjun
2022-08-29 21:29   ` Frank Rowand
2022-08-30  3:05     ` weiyongjun (A) [this message]
2022-08-30 10:27   ` Mark Brown
2022-08-30 19:24     ` Frank Rowand
2022-08-31  4:44       ` weiyongjun (A)
2022-08-26 14:43 ` [PATCH -next 4/4] spi: mockup: Add documentation Wei Yongjun
2022-08-30 18:21   ` Mark Brown
2022-08-30 19:08 ` [PATCH -next 0/4] spi: Introduce BPF based SPI mockup controller Mark Brown
2022-09-01 10:38   ` Mark Brown
2022-09-01 12:23   ` weiyongjun (A)

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=4eab3d1a-199f-fdfe-8d8f-3369eeefde47@huawei.com \
    --to=weiyongjun1@huawei.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=robh+dt@kernel.org \
    --cc=rostedt@goodmis.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).