[PATCH v5 06/11] hwmon: Add Apple Silicon SMC hwmon driver
Dan Carpenter
dan.carpenter at linaro.org
Fri Nov 28 00:10:39 PST 2025
On Wed, Nov 12, 2025 at 09:16:52PM +1000, James Calligeros wrote:
> +static int macsmc_hwmon_populate_sensors(struct macsmc_hwmon *hwmon,
> + struct device_node *hwmon_node)
> +{
> + struct device_node *key_node __maybe_unused;
The for_each_child_of_node_with_prefix() macros declare key_node so this
declaration is never used so far as I can see. I thought Sparse had a
warning where we declared shadow variables where two variables have the
same name but it doesn't complain here. #strange
> + struct macsmc_hwmon_sensor *sensor;
> + u32 n_current = 0, n_fan = 0, n_power = 0, n_temperature = 0, n_voltage = 0;
> +
> + for_each_child_of_node_with_prefix(hwmon_node, key_node, "current-") {
^^^^^^^^
regards,
dan carpenter
> + n_current++;
> + }
> +
> + if (n_current) {
> + hwmon->curr.sensors = devm_kcalloc(hwmon->dev, n_current,
> + sizeof(struct macsmc_hwmon_sensor), GFP_KERNEL);
> + if (!hwmon->curr.sensors)
> + return -ENOMEM;
> +
> + for_each_child_of_node_with_prefix(hwmon_node, key_node, "current-") {
> + sensor = &hwmon->curr.sensors[hwmon->curr.count];
> + if (!macsmc_hwmon_create_sensor(hwmon->dev, hwmon->smc, key_node, sensor)) {
> + sensor->attrs = HWMON_C_INPUT;
> +
> + if (*sensor->label)
> + sensor->attrs |= HWMON_C_LABEL;
> +
> + hwmon->curr.count++;
> + }
> + }
> + }
> +
> + for_each_child_of_node_with_prefix(hwmon_node, key_node, "fan-") {
> + n_fan++;
> + }
> +
> + if (n_fan) {
> + hwmon->fan.fans = devm_kcalloc(hwmon->dev, n_fan,
> + sizeof(struct macsmc_hwmon_fan), GFP_KERNEL);
> + if (!hwmon->fan.fans)
> + return -ENOMEM;
> +
> + for_each_child_of_node_with_prefix(hwmon_node, key_node, "fan-") {
> + if (!macsmc_hwmon_create_fan(hwmon->dev, hwmon->smc, key_node,
> + &hwmon->fan.fans[hwmon->fan.count]))
> + hwmon->fan.count++;
> + }
> + }
> +
> + for_each_child_of_node_with_prefix(hwmon_node, key_node, "power-") {
> + n_power++;
> + }
> +
> + if (n_power) {
> + hwmon->power.sensors = devm_kcalloc(hwmon->dev, n_power,
> + sizeof(struct macsmc_hwmon_sensor), GFP_KERNEL);
> + if (!hwmon->power.sensors)
> + return -ENOMEM;
> +
> + for_each_child_of_node_with_prefix(hwmon_node, key_node, "power-") {
> + sensor = &hwmon->power.sensors[hwmon->power.count];
> + if (!macsmc_hwmon_create_sensor(hwmon->dev, hwmon->smc, key_node, sensor)) {
> + sensor->attrs = HWMON_P_INPUT;
> +
> + if (*sensor->label)
> + sensor->attrs |= HWMON_P_LABEL;
> +
> + hwmon->power.count++;
> + }
> + }
> + }
> +
> + for_each_child_of_node_with_prefix(hwmon_node, key_node, "temperature-") {
> + n_temperature++;
> + }
> +
> + if (n_temperature) {
> + hwmon->temp.sensors = devm_kcalloc(hwmon->dev, n_temperature,
> + sizeof(struct macsmc_hwmon_sensor), GFP_KERNEL);
> + if (!hwmon->temp.sensors)
> + return -ENOMEM;
> +
> + for_each_child_of_node_with_prefix(hwmon_node, key_node, "temperature-") {
> + sensor = &hwmon->temp.sensors[hwmon->temp.count];
> + if (!macsmc_hwmon_create_sensor(hwmon->dev, hwmon->smc, key_node, sensor)) {
> + sensor->attrs = HWMON_T_INPUT;
> +
> + if (*sensor->label)
> + sensor->attrs |= HWMON_T_LABEL;
> +
> + hwmon->temp.count++;
> + }
> + }
> + }
> +
> + for_each_child_of_node_with_prefix(hwmon_node, key_node, "voltage-") {
> + n_voltage++;
> + }
> +
> + if (n_voltage) {
> + hwmon->volt.sensors = devm_kcalloc(hwmon->dev, n_voltage,
> + sizeof(struct macsmc_hwmon_sensor), GFP_KERNEL);
> + if (!hwmon->volt.sensors)
> + return -ENOMEM;
> +
> + for_each_child_of_node_with_prefix(hwmon_node, key_node, "volt-") {
> + sensor = &hwmon->temp.sensors[hwmon->temp.count];
> + if (!macsmc_hwmon_create_sensor(hwmon->dev, hwmon->smc, key_node, sensor)) {
> + sensor->attrs = HWMON_I_INPUT;
> +
> + if (*sensor->label)
> + sensor->attrs |= HWMON_I_LABEL;
> +
> + hwmon->volt.count++;
> + }
> + }
> + }
> +
> + return 0;
> +}
More information about the linux-arm-kernel
mailing list