Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9964213ybi; Wed, 24 Jul 2019 13:09:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzG8wnB0JigiS9J5Hg9MydzZzQkIk30QAKfspoOUJaVCnliLpjo5kt2BjyGXzL3erSzKf43 X-Received: by 2002:a17:902:f01:: with SMTP id 1mr87005042ply.170.1563998979460; Wed, 24 Jul 2019 13:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563998979; cv=none; d=google.com; s=arc-20160816; b=UGJMj6ACig2btS0xBlAMuhzMqWroPXhGkuwirhUEAWCpRRbo+rTIW2AAS4M8dGYH58 nRDmxNFKbO+rA1G/Ym+zo9wX4jNAdXquUZex6aKorir/+1DNPn3zjjZX3YqbXRn90fNs 1ly2jKUwBBRZzcctJgG7EaZHG2SbwxZi10GBlsNm2A4Fwbrpg6s5J2Z/JHtLxP4KhaDK wLmFN/AVKXPkCzJ0679JWmZzY8JKJDa53Wh5xx9F0ZveqZ08MRnxsounGm9Ig/nbq2e6 D3ZIQ9KgWwkjrmraEn0BSSGopdoLrfHVBYzsWH6R2+TsHbUDM+kE6wr3OJjhg0rDcQgb cfgw== 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=6hK5CmzCfQ1vZFiFZDDwgliQAsMbtbgZmZOhJB2VR+s=; b=eXCvUCN8tS7J9YxCaHD9r4yDfGaqrlWfw/W1p6tL/w9Hv44sCzu0WPlpIZE5ev2OLN NwfFom5yu9L+FnoF9cyHtxInUP3qJuhjrUjdKAOHe95E6lYP9pPCsDJnBX3Vw2c46CJn swipT7q7fsO9biiPAdvuhLDYuiUKNd0tSNPaAq4BPhPFYnNqMzdwkGg2zgT+jcjxYHSi 5Ne4Esqist1LT0q5oerqthyF2Dt6Oj7lzLMHczxfoVX8c7GXkZrq+o1Azg8/iu6EQdoS 1r+eLsCdoQXXj2A9orKTIrwcM89WcnbOVl4PjgbvcADnr7zEz/tFiEmrfPJJbNLXClj9 XYUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vJrzqiZ6; 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 r17si14509991pgg.155.2019.07.24.13.09.23; Wed, 24 Jul 2019 13:09:39 -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=vJrzqiZ6; 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 S2405863AbfGXUDf (ORCPT + 99 others); Wed, 24 Jul 2019 16:03:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:53808 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405711AbfGXUDZ (ORCPT ); Wed, 24 Jul 2019 16:03:25 -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 6B0C5214AF; Wed, 24 Jul 2019 20:03:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563998604; bh=MOzaUKXzgJyKrXteXF4eC8jRmJE1AEfBTHUskOOxV0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vJrzqiZ6kXGYxstVsKTlJobObFeZNx2lFf0+LSDGuvVCai6wUMfLGMq4Ds4tVaVdz qTrdyzgH9YGbmTmq1+v0ZEajpwqkub4J/Ckdj5unV1Gt/krGd9VJM8PPkc54NBSy/Z ZmkPTOyctbnUTeI6/+F/n542rz34aoglrKpxs7jQ= 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.19 052/271] net: sfp: add mutex to prevent concurrent state checks Date: Wed, 24 Jul 2019 21:18:41 +0200 Message-Id: <20190724191659.617596768@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@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 8807a806cc47..418522aa2f71 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -185,10 +185,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; @@ -1718,6 +1719,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; @@ -1743,6 +1745,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) @@ -1773,6 +1776,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