Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751896AbdFAJfP (ORCPT ); Thu, 1 Jun 2017 05:35:15 -0400 Received: from m12-14.163.com ([220.181.12.14]:33327 "EHLO m12-14.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751661AbdFAJdV (ORCPT ); Thu, 1 Jun 2017 05:33:21 -0400 From: Jia-Ju Bai To: perex@perex.cz, tiwai@suse.com Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] oss: Fix a sleep-in-atomic bug in midi_outc Date: Thu, 1 Jun 2017 17:33:43 +0800 Message-Id: <1496309623-23072-1-git-send-email-baijiaju1990@163.com> X-Mailer: git-send-email 1.7.9.5 X-CM-TRANSID: DsCowABnpGDu3i9ZglN4IQ--.20806S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7XryfCw18tFy5ZrWDtF4DXFb_yoWfurXEgw 4FgFy8Xw43JrZI9w18ArW3Xr4xKw15Jr18Gws3tr4ayr4Yqa98JrWDJF93WFn5ua1fAa1S qrWYgw4Sk3429jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUjqNtDUUUUU== X-Originating-IP: [166.111.70.19] X-CM-SenderInfo: xedlyx5dmximizq6il2tof0z/1tbiHgfpelSIVWd0OAABsp Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 912 Lines: 30 The driver may sleep under a spin lock, and the function call path is: midi_outc (acquire the lock by spin_lock_irqsave) oss_broken_sleep_on schedule_timeout --> may sleep To fix it, the lock is released before oss_broken_sleep_on, and the lock is acquired again after this function. Signed-off-by: Jia-Ju Bai --- sound/oss/sequencer.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sound/oss/sequencer.c b/sound/oss/sequencer.c index f19da4b..3d95d752 100644 --- a/sound/oss/sequencer.c +++ b/sound/oss/sequencer.c @@ -1211,7 +1211,9 @@ static void midi_outc(int dev, unsigned char data) spin_lock_irqsave(&lock,flags); while (n && !midi_devs[dev]->outputc(dev, data)) { + spin_unlock_irqrestore(&lock, flags); oss_broken_sleep_on(&seq_sleeper, HZ/25); + spin_lock_irqsave(&lock, flags); n--; } spin_unlock_irqrestore(&lock,flags); -- 1.7.9.5