lkml.org 
[lkml]   [2021]   [Oct]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v2 2/2] thermal: add a virtual sensor to aggregate temperatures
On Thu, Oct 7, 2021 at 6:38 PM Rafael J. Wysocki <rafael@kernel.org> wrote:

[cut]

> > +static int virtual_thermal_sensor_probe(struct platform_device *pdev)
> > +{
> > + struct virtual_thermal_sensor *sensor;
> > + struct device *dev = &pdev->dev;
> > + struct of_phandle_args args;
> > + u32 type;
> > + int ret;
> > + int i;
> > +
> > + sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
> > + if (!sensor)
> > + return -ENOMEM;
> > +
> > + sensor->count = of_count_phandle_with_args(dev->of_node,
> > + "thermal-sensors",
> > + "#thermal-sensor-cells");
> > + if (sensor->count <= 0)
> > + return -EINVAL;
> > +
> > + sensor->sensors = devm_kmalloc_array(dev, sensor->count,
> > + sizeof(*sensor->sensors),
> > + GFP_KERNEL);
> > + if (!sensor->sensors)
> > + return -ENOMEM;
> > +
> > + for (i = 0; i < sensor->count; i++) {
> > + ret = of_parse_phandle_with_args(dev->of_node,
> > + "thermal-sensors",
> > + "#thermal-sensor-cells",
> > + i,
> > + &args);
> > + if (ret)
> > + return ret;
> > +
> > + ret = virtual_sensor_add_sensor(sensor, args, i);
> > + if (ret)
> > + return ret;

One more issue that escaped me earlier is that if the hardware sensor
being looked for is not there in the thermal_sensors list at this
point (say because it has not been added to it yet by whoever is
expected to do that), the above will return -ENODEV and all probe will
fail without a way to retry.

It would be better to return -EPROBE_DEFER from here IIUC.

However, this still wouldn't address a more general issue that if the
hardware sensor gets unregistered and then registered again (eg. by
unloading and reloading a module managing it), it will not be added
back to the corresponding virtual sensor's data set. This should not
be very hard to address and it would take care of the above
initialization ordering issue automatically.

\
 
 \ /
  Last update: 2021-10-09 16:47    [W:0.084 / U:0.340 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site