Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3902703ybi; Mon, 29 Jul 2019 15:01:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEgiY3OOjuZdXetmTNMVnIP4boHs8I7s6jCTjCTTu7FNLyYUganjpv/fvBXRbKytjHxoPA X-Received: by 2002:a17:902:aa88:: with SMTP id d8mr106325188plr.274.1564437683490; Mon, 29 Jul 2019 15:01:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564437683; cv=none; d=google.com; s=arc-20160816; b=CGc0kogdjhPVJW+Ihj1VqeiRnQnYUWKjg2LgUgXcmELGT+3BqVN5wfS+IYRKmZdLQ7 XoZlSU+CXFrpdIDY3qPhEMS7trw6x99OB7Otu9Um1+thqzSO8LjiYjU4NSldx22BrjCu dMExSR75Jy5qC9zGPRKddASTge+HFjkl6m2ARDAHAtzP1dw/X0/evu1S2l4DcxFKPiw8 y/db0Hkv/waw4xk0u5imNsHfQ2p8xh9IlnM7ihdJONQmI4Qjml8ddJABmdoR4hdze/2Q EQ+h87yL26YHUYOyNPndjVbgO+dxwf8Ct4vWQ91vuWmBTF7XTbaqMA3WUpfUW2TSrHQG er0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1E8t6Cz+Ql548usCAYwK3MlDq/UIC+nY6K6dTxs2P6Q=; b=gMSUOedf5kUjQxUne0vv9dwH2oA8aQktO35bTsujegiqC4vkaGqQ7A12kVctrQmcXj vRRMZZYk+O0D6zY1xrWKgyGgeqnp3+KOcFu0CoyR8HtYO6wdhU+Tgbm7A9bzaxs23nrQ JIHB85e1/KYBeeFXs74/NYbI451SH+Z/MaZ1CroG0q1WNYHLAWWh4vizqWySrzh8oWoe Z0kpzmdX8ewEcBYn3jb8qPQehVL5r4LNoE0GAGIiF0aS4u2bOSWoNL8G0vWtD/nx1CmW vhIcUN93qbr4GnqSRIQZ1c6YOl7FUxeE887jOWjG/0F/9PWmUys/eKiUCAYkA9Z5K4OA jR2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XUXa9r07; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t2si31634154pgq.488.2019.07.29.15.01.08; Mon, 29 Jul 2019 15:01:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XUXa9r07; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729640AbfG2TZZ (ORCPT + 99 others); Mon, 29 Jul 2019 15:25:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:37684 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728746AbfG2TZY (ORCPT ); Mon, 29 Jul 2019 15:25:24 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B2EE320C01; Mon, 29 Jul 2019 19:25:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428323; bh=OUn9xTpSoelEjjstaQwdtzxYPwUI7JFY53i+XxSV/4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XUXa9r07/tixa8KhaRAQ9lpbESSFXDTiP6tC5/azjQXYVephFRemMSqvxFwnyqGmi UWmv0wz4fndQUB9Ze+aHM6Jcs//RaW/YHMXunvz92Wlprffxn7t8RZKY8ICYSav2vI xCsqInlDxYj2I8kFzSI0WdRaqQe8ZvrX07AFRhvo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Russell King , Robert Hancock , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 039/293] net: sfp: add mutex to prevent concurrent state checks Date: Mon, 29 Jul 2019 21:18:50 +0200 Message-Id: <20190729190825.439396977@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 2158e856f56bb762ef90f3ec244d41a519826f75 ] sfp_check_state can potentially be called by both a threaded IRQ handler and delayed work. If it is concurrently called, it could result in incorrect state management. Add a st_mutex to protect the state - this lock gets taken outside of code that checks and handle state changes, and the existing sm_mutex nests inside of it. Suggested-by: Russell King Signed-off-by: Robert Hancock Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/phy/sfp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index 2dcb25aa0452..9cef89fe410d 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -115,10 +115,11 @@ struct sfp { struct gpio_desc *gpio[GPIO_MAX]; bool attached; + struct mutex st_mutex; /* Protects state */ unsigned int state; struct delayed_work poll; struct delayed_work timeout; - struct mutex sm_mutex; + struct mutex sm_mutex; /* Protects state machine */ unsigned char sm_mod_state; unsigned char sm_dev_state; unsigned short sm_state; @@ -738,6 +739,7 @@ static void sfp_check_state(struct sfp *sfp) { unsigned int state, i, changed; + mutex_lock(&sfp->st_mutex); state = sfp_get_state(sfp); changed = state ^ sfp->state; changed &= SFP_F_PRESENT | SFP_F_LOS | SFP_F_TX_FAULT; @@ -763,6 +765,7 @@ static void sfp_check_state(struct sfp *sfp) sfp_sm_event(sfp, state & SFP_F_LOS ? SFP_E_LOS_HIGH : SFP_E_LOS_LOW); rtnl_unlock(); + mutex_unlock(&sfp->st_mutex); } static irqreturn_t sfp_irq(int irq, void *data) @@ -793,6 +796,7 @@ static struct sfp *sfp_alloc(struct device *dev) sfp->dev = dev; mutex_init(&sfp->sm_mutex); + mutex_init(&sfp->st_mutex); INIT_DELAYED_WORK(&sfp->poll, sfp_poll); INIT_DELAYED_WORK(&sfp->timeout, sfp_timeout); -- 2.20.1