diff mbox series

[4/5] thermal/core: Enforce paired .bind/.unbind callbacks

Message ID 20230324070807.6342-4-rui.zhang@intel.com (mailing list archive)
State Not Applicable, archived
Headers show
Series [v2,1/5] thermal/core: Update cooling device during thermal zone unregistration | expand

Commit Message

Zhang, Rui March 24, 2023, 7:08 a.m. UTC
The .bind/.unbind callbacks are designed to allow the thermal zone
device to bind to/unbind from a matched cooling device, with thermal
instances created/deleted.

In this sense, .bind/.unbind callbacks must exist in pairs.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
 drivers/thermal/thermal_core.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Rafael J. Wysocki March 24, 2023, 1:24 p.m. UTC | #1
On Fri, Mar 24, 2023 at 8:08 AM Zhang Rui <rui.zhang@intel.com> wrote:
>
> The .bind/.unbind callbacks are designed to allow the thermal zone
> device to bind to/unbind from a matched cooling device, with thermal
> instances created/deleted.
>
> In this sense, .bind/.unbind callbacks must exist in pairs.
>
> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
> ---
>  drivers/thermal/thermal_core.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 5225d65fb0e0..9c447f22cb39 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -1258,6 +1258,11 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
>         if (num_trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp) && !trips)
>                 return ERR_PTR(-EINVAL);
>
> +       if ((ops->bind && !ops->unbind) || (!ops->bind && ops->unbind)) {

This can be written as

        if (!!ops->bind != !!ops->unbind) {

> +               pr_err("Thermal zone device .bind/.unbind not paired\n");

And surely none of the existing drivers do that?  Because it would be
a functional regression if they did.

> +               return ERR_PTR(-EINVAL);
> +       }
> +
>         if (!thermal_class)
>                 return ERR_PTR(-ENODEV);
>
> --
Rafael J. Wysocki March 24, 2023, 1:25 p.m. UTC | #2
On Fri, Mar 24, 2023 at 2:24 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Fri, Mar 24, 2023 at 8:08 AM Zhang Rui <rui.zhang@intel.com> wrote:
> >
> > The .bind/.unbind callbacks are designed to allow the thermal zone
> > device to bind to/unbind from a matched cooling device, with thermal
> > instances created/deleted.
> >
> > In this sense, .bind/.unbind callbacks must exist in pairs.
> >
> > Signed-off-by: Zhang Rui <rui.zhang@intel.com>
> > ---
> >  drivers/thermal/thermal_core.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> > index 5225d65fb0e0..9c447f22cb39 100644
> > --- a/drivers/thermal/thermal_core.c
> > +++ b/drivers/thermal/thermal_core.c
> > @@ -1258,6 +1258,11 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
> >         if (num_trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp) && !trips)
> >                 return ERR_PTR(-EINVAL);
> >
> > +       if ((ops->bind && !ops->unbind) || (!ops->bind && ops->unbind)) {
>
> This can be written as
>
>         if (!!ops->bind != !!ops->unbind) {

Or even

        if (!ops->bind != !ops->unbind) {

for that matter.

>
> > +               pr_err("Thermal zone device .bind/.unbind not paired\n");
>
> And surely none of the existing drivers do that?  Because it would be
> a functional regression if they did.
>
> > +               return ERR_PTR(-EINVAL);
> > +       }
> > +
> >         if (!thermal_class)
> >                 return ERR_PTR(-ENODEV);
> >
> > --
Zhang, Rui March 27, 2023, 3:03 p.m. UTC | #3
On Fri, 2023-03-24 at 14:24 +0100, Rafael J. Wysocki wrote:
> On Fri, Mar 24, 2023 at 8:08 AM Zhang Rui <rui.zhang@intel.com>
> wrote:
> > The .bind/.unbind callbacks are designed to allow the thermal zone
> > device to bind to/unbind from a matched cooling device, with
> > thermal
> > instances created/deleted.
> > 
> > In this sense, .bind/.unbind callbacks must exist in pairs.
> > 
> > Signed-off-by: Zhang Rui <rui.zhang@intel.com>
> > ---
> >  drivers/thermal/thermal_core.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> > 
> > diff --git a/drivers/thermal/thermal_core.c
> > b/drivers/thermal/thermal_core.c
> > index 5225d65fb0e0..9c447f22cb39 100644
> > --- a/drivers/thermal/thermal_core.c
> > +++ b/drivers/thermal/thermal_core.c
> > @@ -1258,6 +1258,11 @@
> > thermal_zone_device_register_with_trips(const char *type, struct
> > thermal_trip *t
> >         if (num_trips > 0 && (!ops->get_trip_type || !ops-
> > >get_trip_temp) && !trips)
> >                 return ERR_PTR(-EINVAL);
> > 
> > +       if ((ops->bind && !ops->unbind) || (!ops->bind && ops-
> > >unbind)) {
> 
> This can be written as
> 
>         if (!!ops->bind != !!ops->unbind) {
> 
> > +               pr_err("Thermal zone device .bind/.unbind not
> > paired\n");
> 
> And surely none of the existing drivers do that?  Because it would be
> a functional regression if they did.

Yeah, I did a check and all drivers provide .bind/.unbind callbacks in
pairs.

Hi, Daniel,
I know you're dealing with various of thermal drivers recently, are you
aware of any exceptions?

thanks,
rui
diff mbox series

Patch

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 5225d65fb0e0..9c447f22cb39 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1258,6 +1258,11 @@  thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
 	if (num_trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp) && !trips)
 		return ERR_PTR(-EINVAL);
 
+	if ((ops->bind && !ops->unbind) || (!ops->bind && ops->unbind)) {
+		pr_err("Thermal zone device .bind/.unbind not paired\n");
+		return ERR_PTR(-EINVAL);
+	}
+
 	if (!thermal_class)
 		return ERR_PTR(-ENODEV);