From patchwork Thu Oct 13 21:29:23 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: sjur.brandeland@stericsson.com X-Patchwork-Id: 119651 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id DEA75B71BF for ; Fri, 14 Oct 2011 09:30:07 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754762Ab1JMW36 (ORCPT ); Thu, 13 Oct 2011 18:29:58 -0400 Received: from eterpe-smout.broadpark.no ([80.202.8.16]:41517 "EHLO eterpe-smout.broadpark.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753941Ab1JMW35 (ORCPT ); Thu, 13 Oct 2011 18:29:57 -0400 X-Greylist: delayed 3602 seconds by postgrey-1.27 at vger.kernel.org; Thu, 13 Oct 2011 18:29:55 EDT MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; charset=UTF-8 Received: from ignis-smin.broadpark.no ([80.202.8.11]) by eterpe-smout.broadpark.no (Sun Java(tm) System Messaging Server 7u3-15.01 64bit (built Feb 12 2010)) with ESMTP id <0LT0001DXX1M7670@eterpe-smout.broadpark.no> for netdev@vger.kernel.org; Thu, 13 Oct 2011 23:29:46 +0200 (CEST) Received: from localhost.localdomain ([80.203.143.169]) by ignis-smin.broadpark.no (Sun Java(tm) System Messaging Server 7u3-15.01 64bit (built Feb 12 2010)) with ESMTP id <0LT000HN3X1J7Y00@ignis-smin.broadpark.no> for netdev@vger.kernel.org; Thu, 13 Oct 2011 23:29:46 +0200 (CEST) From: =?UTF-8?q?Sjur=20Br=C3=A6ndeland?= To: David Miller , netdev@vger.kernel.org Cc: dmitry.tarnyagin@stericsson.com, daniel.martensson@stericsson.com, =?UTF-8?q?Sjur=20Br=C3=A6ndeland?= Subject: [PATCH 2/8] caif-hsi: Fixing a race condition in the caif_hsi code Date: Thu, 13 Oct 2011 23:29:23 +0200 Message-id: <1318541369-8141-3-git-send-email-sjur.brandeland@stericsson.com> X-Mailer: git-send-email 1.7.0.4 In-reply-to: <1318541369-8141-1-git-send-email-sjur.brandeland@stericsson.com> References: <1318541369-8141-1-git-send-email-sjur.brandeland@stericsson.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmitry Tarnyagin cfhsi->tx_state was not protected by a spin lock. TX soft-irq could interrupt cfhsi_tx_done_work work leading to inconsistent state of the driver. Signed-off-by: Sjur Brændeland --- drivers/net/caif/caif_hsi.c | 25 ++++++++++++++++++------- 1 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c index 1937813..36da27b 100644 --- a/drivers/net/caif/caif_hsi.c +++ b/drivers/net/caif/caif_hsi.c @@ -304,14 +304,22 @@ static void cfhsi_tx_done_work(struct work_struct *work) spin_unlock_bh(&cfhsi->lock); /* Create HSI frame. */ - len = cfhsi_tx_frm(desc, cfhsi); - if (!len) { - cfhsi->tx_state = CFHSI_TX_STATE_IDLE; - /* Start inactivity timer. */ - mod_timer(&cfhsi->timer, + do { + len = cfhsi_tx_frm(desc, cfhsi); + if (!len) { + spin_lock_bh(&cfhsi->lock); + if (unlikely(skb_peek(&cfhsi->qhead))) { + spin_unlock_bh(&cfhsi->lock); + continue; + } + cfhsi->tx_state = CFHSI_TX_STATE_IDLE; + /* Start inactivity timer. */ + mod_timer(&cfhsi->timer, jiffies + CFHSI_INACTIVITY_TOUT); - break; - } + spin_unlock_bh(&cfhsi->lock); + goto done; + } + } while (!len); /* Set up new transfer. */ res = cfhsi->dev->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->dev); @@ -320,6 +328,9 @@ static void cfhsi_tx_done_work(struct work_struct *work) __func__, res); } } while (res < 0); + +done: + return; } static void cfhsi_tx_done_cb(struct cfhsi_drv *drv)