Skip to content

Commit 099b02d

Browse files
committed
Merge tag 'counter-updates-for-7.2' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/wbg/counter into char-misc-next
William writes: Counter updates for 7.2 Manual mutex lock logic is replaced by lock guards in intel-qep. Additionally, devm_mutex_init() is now used in ftm-quaddec, interrupt-cnt, and intel-qep to handle mutex cleanup automatically. * tag 'counter-updates-for-7.2' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/wbg/counter: counter: intel-qep: Use devm_mutex_init() counter: interrupt-cnt: use devm_mutex_init() counter: ftm-quaddec: use devm_mutex_init() counter: intel-qep: Replace manual mutex logic with lock guards
2 parents da61573 + ca815bb commit 099b02d

3 files changed

Lines changed: 27 additions & 35 deletions

File tree

drivers/counter/ftm-quaddec.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
292292
counter->signals = ftm_quaddec_signals;
293293
counter->num_signals = ARRAY_SIZE(ftm_quaddec_signals);
294294

295-
mutex_init(&ftm->ftm_quaddec_mutex);
295+
ret = devm_mutex_init(&pdev->dev, &ftm->ftm_quaddec_mutex);
296+
if (ret)
297+
return ret;
296298

297299
ftm_quaddec_init(ftm);
298300

drivers/counter/intel-qep.c

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -188,25 +188,21 @@ static int intel_qep_ceiling_write(struct counter_device *counter,
188188
struct counter_count *count, u64 max)
189189
{
190190
struct intel_qep *qep = counter_priv(counter);
191-
int ret = 0;
192191

193192
/* Intel QEP ceiling configuration only supports 32-bit values */
194193
if (max != (u32)max)
195194
return -ERANGE;
196195

197-
mutex_lock(&qep->lock);
198-
if (qep->enabled) {
199-
ret = -EBUSY;
200-
goto out;
201-
}
196+
guard(mutex)(&qep->lock);
197+
198+
if (qep->enabled)
199+
return -EBUSY;
202200

203201
pm_runtime_get_sync(qep->dev);
204202
intel_qep_writel(qep, INTEL_QEPMAX, max);
205203
pm_runtime_put(qep->dev);
206204

207-
out:
208-
mutex_unlock(&qep->lock);
209-
return ret;
205+
return 0;
210206
}
211207

212208
static int intel_qep_enable_read(struct counter_device *counter,
@@ -226,10 +222,11 @@ static int intel_qep_enable_write(struct counter_device *counter,
226222
u32 reg;
227223
bool changed;
228224

229-
mutex_lock(&qep->lock);
225+
guard(mutex)(&qep->lock);
226+
230227
changed = val ^ qep->enabled;
231228
if (!changed)
232-
goto out;
229+
return 0;
233230

234231
pm_runtime_get_sync(qep->dev);
235232
reg = intel_qep_readl(qep, INTEL_QEPCON);
@@ -246,8 +243,6 @@ static int intel_qep_enable_write(struct counter_device *counter,
246243
pm_runtime_put(qep->dev);
247244
qep->enabled = val;
248245

249-
out:
250-
mutex_unlock(&qep->lock);
251246
return 0;
252247
}
253248

@@ -279,7 +274,6 @@ static int intel_qep_spike_filter_ns_write(struct counter_device *counter,
279274
struct intel_qep *qep = counter_priv(counter);
280275
u32 reg;
281276
bool enable;
282-
int ret = 0;
283277

284278
/*
285279
* Spike filter length is (MAX_COUNT + 2) clock periods.
@@ -300,11 +294,10 @@ static int intel_qep_spike_filter_ns_write(struct counter_device *counter,
300294
if (length > INTEL_QEPFLT_MAX_COUNT(length))
301295
return -ERANGE;
302296

303-
mutex_lock(&qep->lock);
304-
if (qep->enabled) {
305-
ret = -EBUSY;
306-
goto out;
307-
}
297+
guard(mutex)(&qep->lock);
298+
299+
if (qep->enabled)
300+
return -EBUSY;
308301

309302
pm_runtime_get_sync(qep->dev);
310303
reg = intel_qep_readl(qep, INTEL_QEPCON);
@@ -316,9 +309,7 @@ static int intel_qep_spike_filter_ns_write(struct counter_device *counter,
316309
intel_qep_writel(qep, INTEL_QEPCON, reg);
317310
pm_runtime_put(qep->dev);
318311

319-
out:
320-
mutex_unlock(&qep->lock);
321-
return ret;
312+
return 0;
322313
}
323314

324315
static int intel_qep_preset_enable_read(struct counter_device *counter,
@@ -342,13 +333,11 @@ static int intel_qep_preset_enable_write(struct counter_device *counter,
342333
{
343334
struct intel_qep *qep = counter_priv(counter);
344335
u32 reg;
345-
int ret = 0;
346336

347-
mutex_lock(&qep->lock);
348-
if (qep->enabled) {
349-
ret = -EBUSY;
350-
goto out;
351-
}
337+
guard(mutex)(&qep->lock);
338+
339+
if (qep->enabled)
340+
return -EBUSY;
352341

353342
pm_runtime_get_sync(qep->dev);
354343
reg = intel_qep_readl(qep, INTEL_QEPCON);
@@ -360,10 +349,7 @@ static int intel_qep_preset_enable_write(struct counter_device *counter,
360349
intel_qep_writel(qep, INTEL_QEPCON, reg);
361350
pm_runtime_put(qep->dev);
362351

363-
out:
364-
mutex_unlock(&qep->lock);
365-
366-
return ret;
352+
return 0;
367353
}
368354

369355
static struct counter_comp intel_qep_count_ext[] = {
@@ -414,7 +400,9 @@ static int intel_qep_probe(struct pci_dev *pci, const struct pci_device_id *id)
414400

415401
qep->dev = dev;
416402
qep->regs = regs;
417-
mutex_init(&qep->lock);
403+
ret = devm_mutex_init(dev, &qep->lock);
404+
if (ret)
405+
return ret;
418406

419407
intel_qep_init(qep);
420408
pci_set_drvdata(pci, qep);

drivers/counter/interrupt-cnt.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
233233
if (ret)
234234
return ret;
235235

236-
mutex_init(&priv->lock);
236+
ret = devm_mutex_init(dev, &priv->lock);
237+
if (ret)
238+
return ret;
237239

238240
ret = devm_counter_add(dev, counter);
239241
if (ret < 0)

0 commit comments

Comments
 (0)