Re: [RFC PATCH 01/57] drivers: s390/cio: Use driver_for_each_device

Suzuki K Poulose
2019-06-14T13:32:45Z

Heiko, Sebastian, Peter,

Please could you review the following patch ?

On 03/06/2019 16:49, Suzuki K Poulose wrote:
> The cio driver use driver_find_device() to find all devices
> to release them before the driver is unregistered. Instead,
> it could easily use a lighter driver_for_each_device() helper
> to iterate over all the devices.
>
> Cc: Sebastian Ott <sebott@linux.ibm.com>
> Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
> Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
> drivers/s390/cio/ccwgroup.c | 18 ++++++++----------
> 1 file changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
> index 4ebf6d4..a006945 100644
> --- a/drivers/s390/cio/ccwgroup.c
> +++ b/drivers/s390/cio/ccwgroup.c
> @@ -581,9 +581,12 @@ int ccwgroup_driver_register(struct ccwgroup_driver *cdriver)
> }
> EXPORT_SYMBOL(ccwgroup_driver_register);
>
> -static int __ccwgroup_match_all(struct device *dev, void *data)
> +static int ccwgroup_release_device(struct device *dev, void *unused)
> {
> - return 1;
> + struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
> +
> + ccwgroup_ungroup(gdev);
> + return 0;
> }
>
> /**
> @@ -594,16 +597,11 @@ static int __ccwgroup_match_all(struct device *dev, void *data)
> */
> void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
> {
> - struct device *dev;
> + int ret;
>
> /* We don't want ccwgroup devices to live longer than their driver. */
> - while ((dev = driver_find_device(&cdriver->driver, NULL, NULL,
> - __ccwgroup_match_all))) {
> - struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
> -
> - ccwgroup_ungroup(gdev);
> - put_device(dev);
> - }
> + ret = driver_for_each_device(&cdriver->driver, NULL, NULL,
> + ccwgroup_release_device);
> driver_unregister(&cdriver->driver);
> }
> EXPORT_SYMBOL(ccwgroup_driver_unregister);
>

Thanks
Suzuki