Commit 505dc0cc7e99279d60f5c3508018682beee22d65

Authored by Guenter Roeck
1 parent b25df2bfbe

hwmon: (via-cputemp) Convert to use devm_ functions

Convert to use devm_ functions to reduce code size and simplify the code.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Showing 1 changed file with 7 additions and 16 deletions Side-by-side Diff

drivers/hwmon/via-cputemp.c
... ... @@ -128,12 +128,10 @@
128 128 int err;
129 129 u32 eax, edx;
130 130  
131   - data = kzalloc(sizeof(struct via_cputemp_data), GFP_KERNEL);
132   - if (!data) {
133   - err = -ENOMEM;
134   - dev_err(&pdev->dev, "Out of memory\n");
135   - goto exit;
136   - }
  131 + data = devm_kzalloc(&pdev->dev, sizeof(struct via_cputemp_data),
  132 + GFP_KERNEL);
  133 + if (!data)
  134 + return -ENOMEM;
137 135  
138 136 data->id = pdev->id;
139 137 data->name = "via_cputemp";
... ... @@ -151,8 +149,7 @@
151 149 data->msr_temp = 0x1423;
152 150 break;
153 151 default:
154   - err = -ENODEV;
155   - goto exit_free;
  152 + return -ENODEV;
156 153 }
157 154  
158 155 /* test if we can access the TEMPERATURE MSR */
159 156  
... ... @@ -160,14 +157,14 @@
160 157 if (err) {
161 158 dev_err(&pdev->dev,
162 159 "Unable to access TEMPERATURE MSR, giving up\n");
163   - goto exit_free;
  160 + return err;
164 161 }
165 162  
166 163 platform_set_drvdata(pdev, data);
167 164  
168 165 err = sysfs_create_group(&pdev->dev.kobj, &via_cputemp_group);
169 166 if (err)
170   - goto exit_free;
  167 + return err;
171 168  
172 169 if (data->msr_vid)
173 170 data->vrm = vid_which_vrm();
... ... @@ -192,10 +189,6 @@
192 189 if (data->vrm)
193 190 device_remove_file(&pdev->dev, &dev_attr_cpu0_vid);
194 191 sysfs_remove_group(&pdev->dev.kobj, &via_cputemp_group);
195   -exit_free:
196   - platform_set_drvdata(pdev, NULL);
197   - kfree(data);
198   -exit:
199 192 return err;
200 193 }
201 194  
... ... @@ -207,8 +200,6 @@
207 200 if (data->vrm)
208 201 device_remove_file(&pdev->dev, &dev_attr_cpu0_vid);
209 202 sysfs_remove_group(&pdev->dev.kobj, &via_cputemp_group);
210   - platform_set_drvdata(pdev, NULL);
211   - kfree(data);
212 203 return 0;
213 204 }
214 205