Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753534AbdFSCyW (ORCPT ); Sun, 18 Jun 2017 22:54:22 -0400 Received: from m12-12.163.com ([220.181.12.12]:54377 "EHLO m12-12.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753258AbdFSCyV (ORCPT ); Sun, 18 Jun 2017 22:54: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: Mon, 19 Jun 2017 10:56:23 +0800 Message-Id: <1497840983-5023-1-git-send-email-baijiaju1990@163.com> X-Mailer: git-send-email 1.7.9.5 X-CM-TRANSID: DMCowABHd6ucPEdZ3yFeDA--.36715S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7XryfCw18tFy5ZrWDtF4DXFb_yoWfurXEgw 4FgFy8Xw43JrZI9w18ArW3Xr4xKw15Jr18Gws3tr4ayr4Yqa98JrWDJF93WFn5ua1fAa1S qrWYgw4Sk3429jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUjzwZDUUUUU== X-Originating-IP: [166.111.70.19] X-CM-SenderInfo: xedlyx5dmximizq6il2tof0z/1tbiYwL7elaDteFTmgAAso 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