Message ID | 20240417051642.788740-1-ashutosh.dixit@intel.com (mailing list archive) |
---|---|
State | Handled Elsewhere |
Headers | show |
Series | [v4] drm/i915/hwmon: Get rid of devm | expand |
Hi Ashutosh, > @@ -839,16 +837,38 @@ void i915_hwmon_register(struct drm_i915_private *i915) > if (!hwm_gt_is_visible(ddat_gt, hwmon_energy, hwmon_energy_input, 0)) > continue; > > - hwmon_dev = devm_hwmon_device_register_with_info(dev, ddat_gt->name, > - ddat_gt, > - &hwm_gt_chip_info, > - NULL); > - if (!IS_ERR(hwmon_dev)) > - ddat_gt->hwmon_dev = hwmon_dev; > + hwmon_dev = hwmon_device_register_with_info(dev, ddat_gt->name, > + ddat_gt, > + &hwm_gt_chip_info, > + NULL); > + if (IS_ERR(hwmon_dev)) > + goto err; here the logic is changing, though. Before we were not leaving if hwmon_device_register_with_info() was returning error. Is this wanted? And why isn't it described in the log? Thanks, Andi > + > + ddat_gt->hwmon_dev = hwmon_dev; > }
On Wed, 17 Apr 2024 01:28:48 -0700, Andi Shyti wrote: > Hi Andi, > > @@ -839,16 +837,38 @@ void i915_hwmon_register(struct drm_i915_private *i915) > > if (!hwm_gt_is_visible(ddat_gt, hwmon_energy, hwmon_energy_input, 0)) > > continue; > > > > - hwmon_dev = devm_hwmon_device_register_with_info(dev, ddat_gt->name, > > - ddat_gt, > > - &hwm_gt_chip_info, > > - NULL); > > - if (!IS_ERR(hwmon_dev)) > > - ddat_gt->hwmon_dev = hwmon_dev; > > + hwmon_dev = hwmon_device_register_with_info(dev, ddat_gt->name, > > + ddat_gt, > > + &hwm_gt_chip_info, > > + NULL); > > + if (IS_ERR(hwmon_dev)) > > + goto err; > > here the logic is changing, though. Before we were not leaving if > hwmon_device_register_with_info() was returning error. > > Is this wanted? And why isn't it described in the log? Not sure if the previous logic was intentional or not, anyway I have restored it in v5 (where I once again forgot to add "PATCH v5" to the Subject but v5 is there in the version log :/). Thanks. -- Ashutosh
diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c index b758fd110c20..1551a40a675e 100644 --- a/drivers/gpu/drm/i915/i915_hwmon.c +++ b/drivers/gpu/drm/i915/i915_hwmon.c @@ -793,7 +793,7 @@ void i915_hwmon_register(struct drm_i915_private *i915) if (!IS_DGFX(i915)) return; - hwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL); + hwmon = kzalloc(sizeof(*hwmon), GFP_KERNEL); if (!hwmon) return; @@ -819,14 +819,12 @@ void i915_hwmon_register(struct drm_i915_private *i915) hwm_get_preregistration_info(i915); /* hwmon_dev points to device hwmon<i> */ - hwmon_dev = devm_hwmon_device_register_with_info(dev, ddat->name, - ddat, - &hwm_chip_info, - hwm_groups); - if (IS_ERR(hwmon_dev)) { - i915->hwmon = NULL; - return; - } + hwmon_dev = hwmon_device_register_with_info(dev, ddat->name, + ddat, + &hwm_chip_info, + hwm_groups); + if (IS_ERR(hwmon_dev)) + goto err; ddat->hwmon_dev = hwmon_dev; @@ -839,16 +837,38 @@ void i915_hwmon_register(struct drm_i915_private *i915) if (!hwm_gt_is_visible(ddat_gt, hwmon_energy, hwmon_energy_input, 0)) continue; - hwmon_dev = devm_hwmon_device_register_with_info(dev, ddat_gt->name, - ddat_gt, - &hwm_gt_chip_info, - NULL); - if (!IS_ERR(hwmon_dev)) - ddat_gt->hwmon_dev = hwmon_dev; + hwmon_dev = hwmon_device_register_with_info(dev, ddat_gt->name, + ddat_gt, + &hwm_gt_chip_info, + NULL); + if (IS_ERR(hwmon_dev)) + goto err; + + ddat_gt->hwmon_dev = hwmon_dev; } + return; +err: + i915_hwmon_unregister(i915); } void i915_hwmon_unregister(struct drm_i915_private *i915) { - fetch_and_zero(&i915->hwmon); + struct i915_hwmon *hwmon = i915->hwmon; + struct intel_gt *gt; + int i; + + if (!hwmon) + return; + + for_each_gt(gt, i915, i) + if (hwmon->ddat_gt[i].hwmon_dev) + hwmon_device_unregister(hwmon->ddat_gt[i].hwmon_dev); + + if (hwmon->ddat.hwmon_dev) + hwmon_device_unregister(hwmon->ddat.hwmon_dev); + + mutex_destroy(&hwmon->hwmon_lock); + + kfree(i915->hwmon); + i915->hwmon = NULL; }