Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Besar Wicaksono <bwicaksono@nvidia.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: "ilkka@os.amperecomputing.com" <ilkka@os.amperecomputing.com>,
	"catalin.marinas@arm.com" <catalin.marinas@arm.com>,
	"will@kernel.org" <will@kernel.org>,
	"mark.rutland@arm.com" <mark.rutland@arm.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-tegra@vger.kernel.org" <linux-tegra@vger.kernel.org>,
	Thierry Reding <treding@nvidia.com>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Vikram Sethi <vsethi@nvidia.com>,
	Richard Wiley <rwiley@nvidia.com>,
	Eric Funsten <efunsten@nvidia.com>
Subject: Re: [PATCH v5] perf: arm_cspmu: Separate Arm and vendor module
Date: Mon, 21 Aug 2023 10:29:22 +0100	[thread overview]
Message-ID: <2f1beb3e-c9df-46c5-fe5d-0d688a730521@arm.com> (raw)
In-Reply-To: <SJ0PR12MB5676F7D0749A35DCB185452EA018A@SJ0PR12MB5676.namprd12.prod.outlook.com>

On 2023-08-19 21:11, Besar Wicaksono wrote:
[...]
>>> +void arm_cspmu_impl_unregister(const struct arm_cspmu_impl_match
>> *impl_match)
>>> +{
>>> +     struct device *dev;
>>> +     struct arm_cspmu_impl_match *match;
>>> +
>>> +     match = arm_cspmu_impl_match_get(impl_match->pmiidr_val);
>>> +
>>> +     WARN_ON(!match);

Nit: do "if (WARN_ON(!match)) return;" rather than indenting almost the 
whole function.

>>> +
>>> +     if (match) {
>>> +             /* Unbind the driver from all matching backend devices. */
>>> +dev_release:
>>> +             dev = driver_find_device(&arm_cspmu_driver.driver, NULL,
>>> +                     match, arm_cspmu_match_device);
>>> +             if (dev) {
>>> +                     device_release_driver(dev);
>>> +                     goto dev_release;
>>> +             }
>>
>> minor nit: We could simply do :
>>
>> static int arm_cspmu_release_driver(struct device *dev, void *data)
>> {
>>          struct arm_cspmu *cspmu =
>> platform_get_drvdata(to_platform_device(dev));
>>
>>          if (cspmu && cspmu->impl.match == match)
>>                  device_release_driver(dev);
>>          return 0;
>> }
>>
>>                  ret = driver_for_each_device(&driver, NULL, match,
>> arm_csmpu_release_driver);
>>
> 
> It doesn’t seem to work for me.
> Is it safe to release while iterating via driver_for_each_device ?

Looking at the klist code it doesn't *obviously* appear safe to modify 
the list during iteration, so probably best not to risk it anyway. 
However, please try to write this loop as an actual loop, e.g.:

	while ((dev = driver_find_device()))
		device_release_driver();

At first glance I thought there was a bug here that it's only processing 
a single device, then eventually I saw the goto and my thought changed 
to "Eww..."

Thanks,
Robin.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2023-08-21  9:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-05 10:47 [PATCH v5] perf: arm_cspmu: Separate Arm and vendor module Besar Wicaksono
2023-07-28 13:22 ` Will Deacon
2023-08-11  0:53   ` Besar Wicaksono
2023-08-11 11:28 ` Suzuki K Poulose
2023-08-19 20:11   ` Besar Wicaksono
2023-08-21  9:29     ` Robin Murphy [this message]
2023-08-18 16:05 ` Will Deacon
2023-08-18 16:06   ` Will Deacon
2023-08-18 16:22     ` Besar Wicaksono

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=2f1beb3e-c9df-46c5-fe5d-0d688a730521@arm.com \
    --to=robin.murphy@arm.com \
    --cc=bwicaksono@nvidia.com \
    --cc=catalin.marinas@arm.com \
    --cc=efunsten@nvidia.com \
    --cc=ilkka@os.amperecomputing.com \
    --cc=jonathanh@nvidia.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=rwiley@nvidia.com \
    --cc=suzuki.poulose@arm.com \
    --cc=treding@nvidia.com \
    --cc=vsethi@nvidia.com \
    --cc=will@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