From patchwork Thu Jan 2 12:07:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 3424821 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EB0B89F295 for ; Thu, 2 Jan 2014 12:16:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E23EA20148 for ; Thu, 2 Jan 2014 12:16:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D7B2B20145 for ; Thu, 2 Jan 2014 12:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751632AbaABMIJ (ORCPT ); Thu, 2 Jan 2014 07:08:09 -0500 Received: from moutng.kundenserver.de ([212.227.17.9]:50868 "EHLO moutng.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751136AbaABMIG (ORCPT ); Thu, 2 Jan 2014 07:08:06 -0500 Received: from wuerfel.lan (HSI-KBW-085-216-031-165.hsi.kabelbw.de [85.216.31.165]) by mrelayeu.kundenserver.de (node=mrbap1) with ESMTP (Nemesis) id 0LjdUG-1VRqE10ydc-00bwni; Thu, 02 Jan 2014 13:08:05 +0100 From: Arnd Bergmann To: linux-kernel@vger.kernel.org Cc: Arnd Bergmann , Hans Verkuil , Mauro Carvalho Chehab , linux-media@vger.kernel.org Subject: [PATCH, RFC 07/30] [media] radio-cadet: avoid interruptible_sleep_on race Date: Thu, 2 Jan 2014 13:07:31 +0100 Message-Id: <1388664474-1710039-8-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1388664474-1710039-1-git-send-email-arnd@arndb.de> References: <1388664474-1710039-1-git-send-email-arnd@arndb.de> X-Provags-ID: V02:K0:ujd1vRKUL97Pusqi1P7A0A9VGBnLzDUZv38AwII1cxD s+IDndcWhPF7SbwHQ3lpmD/BJ4joaWZVILEtlkhgW+0/VSiDxT cONjxuv7CnRWe/fqwelNYeZnxlwrVfiF6A6Zo/NE4zNWRmJ/Tv gBnEqMN2cnFgfLux/NI12WOYCoEDkG3VEuviizb5NgVvG0g05R OBo6i89vzY30rhnqMmowZwzinapuYiRbr/QU+75r6BkfHn2CZo QX89eHKIK4TdOAudPoAgB+045yeY6dUuFhOnH8IjoT+NXgiRYz cqpy4vPzo0ol/i2r4GMbWQcDYl1VPKuDIqARAIjuvIfGpXRf8f laiS55B2FepHN9bDx/QgT38e2aOtiwkwTM/wc/bQS Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP interruptible_sleep_on is racy and going away. This replaces one use in the radio-cadet driver with an open-coded wait loop that lets us check the condition under the mutex but sleep without it. Signed-off-by: Arnd Bergmann Cc: Hans Verkuil Cc: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org --- drivers/media/radio/radio-cadet.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c index 545c04c..67b5bbf 100644 --- a/drivers/media/radio/radio-cadet.c +++ b/drivers/media/radio/radio-cadet.c @@ -39,6 +39,7 @@ #include #include #include /* outb, outb_p */ +#include #include #include #include @@ -323,25 +324,32 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo struct cadet *dev = video_drvdata(file); unsigned char readbuf[RDS_BUFFER]; int i = 0; + DEFINE_WAIT(wait); mutex_lock(&dev->lock); if (dev->rdsstat == 0) cadet_start_rds(dev); - if (dev->rdsin == dev->rdsout) { + while (1) { + prepare_to_wait(&dev->read_queue, &wait, TASK_INTERRUPTIBLE); + if (dev->rdsin != dev->rdsout) + break; + if (file->f_flags & O_NONBLOCK) { i = -EWOULDBLOCK; goto unlock; } mutex_unlock(&dev->lock); - interruptible_sleep_on(&dev->read_queue); + schedule(); mutex_lock(&dev->lock); } + while (i < count && dev->rdsin != dev->rdsout) readbuf[i++] = dev->rdsbuf[dev->rdsout++]; if (i && copy_to_user(data, readbuf, i)) i = -EFAULT; unlock: + finish_wait(&dev->read_queue, &wait); mutex_unlock(&dev->lock); return i; }