Drivers may call ptp_find_pin() from their enable callback; that helper requires the caller to hold pincfg_mux. The ioctl paths hold the lock, but the EXTTS, PPS and periodic-output sysfs stores do not. Take pincfg_mux around the three sysfs callbacks. Leave existing validation, permission checks and callback error handling unchanged. Return -ERESTARTSYS if lock acquisition is interrupted. Developed with coding-assistant support during review and validation. Fixes: 62582a7ee783 ("ptp: Avoid deadlocks in the programmable pin code.") Link: https://lore.kernel.org/r/179579937722.3135.2568812643544816671@kernel.org Signed-off-by: Ahmad Byagowi --- drivers/ptp/ptp_sysfs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c index 8e0e0aa09981..90fdddc1e6a7 100644 --- a/drivers/ptp/ptp_sysfs.c +++ b/drivers/ptp/ptp_sysfs.c @@ -60,7 +60,10 @@ static ssize_t extts_enable_store(struct device *dev, if (req.extts.index >= ops->n_ext_ts) goto out; + if (mutex_lock_interruptible(&ptp->pincfg_mux)) + return -ERESTARTSYS; err = ops->enable(ops, &req, enable ? 1 : 0); + mutex_unlock(&ptp->pincfg_mux); if (err) goto out; @@ -130,7 +133,10 @@ static ssize_t period_store(struct device *dev, goto out; enable = req.perout.period.sec || req.perout.period.nsec; + if (mutex_lock_interruptible(&ptp->pincfg_mux)) + return -ERESTARTSYS; err = ops->enable(ops, &req, enable); + mutex_unlock(&ptp->pincfg_mux); if (err) goto out; @@ -157,7 +163,10 @@ static ssize_t pps_enable_store(struct device *dev, if (cnt != 1) goto out; + if (mutex_lock_interruptible(&ptp->pincfg_mux)) + return -ERESTARTSYS; err = ops->enable(ops, &req, enable ? 1 : 0); + mutex_unlock(&ptp->pincfg_mux); if (err) goto out; base-commit: 4392bb809812ac79449cd0cf1f5e00469ee102d1 -- 2.54.0 (Apple Git-157)