Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp491933ybl; Tue, 28 Jan 2020 06:48:15 -0800 (PST) X-Google-Smtp-Source: APXvYqwZX9TDvhDFeydKvoGe53bhSlnNezwUNqtWL00wDbD6AX1NC0Ri1w+eRsHWcAns1ZAMF/W4 X-Received: by 2002:a9d:21f5:: with SMTP id s108mr17464841otb.152.1580222895151; Tue, 28 Jan 2020 06:48:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580222895; cv=none; d=google.com; s=arc-20160816; b=u3k+xBtovTEe3pF0N8c5n3wTSnm1hEtG8fH/tcc9LipDkazRA4l8IZiqvKypU/Ftgz qZrtInY7izeZo3xtwBQrxUWHhWFbJUjyOe8JjhWDLc2N28hrHVvzhmWn+Khmz5folW0D Zv7MHRnujnjPlVCseglriumP+P3Lz1jVRWspeQKR1sLJYH57eBdoSDoG7tIUzzd7vEBL IiSzH6HNNfGmwiXRjpzhLq34olKubQXil4cJZbN/jIwQLOGfqYnm5XrSOrfPWBsRcjK4 aXlscFBL/erR6KP4+m6TjSJseDHGOuyVTGm/C+yCm4jLAVvrRP/0fkvDwGCKsEXq3OcG FDnA== 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=kA5QQiUnDy4SwJdZtKgEYSWjQ3celAuwS/mxQSsI2o0=; b=ACsejxjMX4PIo/pks/x3fdb+6og6VDUZkWL9M2G298pt+XR4HyHKX0MhhhBtdzRjjB OZvtAg3o0+y76ugzRG5ep2AS4FwjJ81kQX/KULl5DaoyQoLHqhVM+1RfEnZ0d+Al/H5C lblxNZxDEkuL7cwdGUxPu/ukOB2R2u5djlrhgRAuNAl54x7R9ykKWJ3xkKIU4jizn4OD 3mBKNQr83w3UA06BXfCpguCe+8sMr0s2nlMqCZOs42XYp8lpGVmntNDs8LzgjN5PjQaA R+xPy8CqVF6Z1aflJ+a83BHT3v70wcmJOpO3M3jrk0aDesR36cfT6ZoFXY4xKrCcmkB1 mMng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gL60sfiX; 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 y9si5102891oiy.81.2020.01.28.06.48.03; Tue, 28 Jan 2020 06:48:15 -0800 (PST) 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=gL60sfiX; 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 S1731193AbgA1OVB (ORCPT + 99 others); Tue, 28 Jan 2020 09:21:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:46076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731178AbgA1OU7 (ORCPT ); Tue, 28 Jan 2020 09:20:59 -0500 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 3080A2468A; Tue, 28 Jan 2020 14:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221258; bh=BDmzMUOv+jwCWIgzcr7uhDx7cxYkavGXJYJFdjJ7oTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gL60sfiX9gs5B8b0I8ug2B61HTS5a2CvWjk/btbtTr5P7ysq2Aq+vdjcT3uZH9wEr 90b+KCeCNUM8apN2hbqgHrEv/L4jTtZnOLUgH5zsSPWAvyrLpYucSiHTin48/Kf/rz fbH95WiFqtPcHaX7iDIcDzcAlXW4cYS1k0NodK0U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guenter Roeck , Sasha Levin Subject: [PATCH 4.9 116/271] hwmon: (w83627hf) Use request_muxed_region for Super-IO accesses Date: Tue, 28 Jan 2020 15:04:25 +0100 Message-Id: <20200128135901.212745091@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135852.449088278@linuxfoundation.org> References: <20200128135852.449088278@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 From: Guenter Roeck [ Upstream commit e95fd518d05bfc087da6fcdea4900a57cfb083bd ] Super-IO accesses may fail on a system with no or unmapped LPC bus. Also, other drivers may attempt to access the LPC bus at the same time, resulting in undefined behavior. Use request_muxed_region() to ensure that IO access on the requested address space is supported, and to ensure that access by multiple drivers is synchronized. Fixes: b72656dbc491 ("hwmon: (w83627hf) Stop using globals for I/O port numbers") Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/w83627hf.c | 42 +++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c index 721295b9a0517..43c0f89cefdf0 100644 --- a/drivers/hwmon/w83627hf.c +++ b/drivers/hwmon/w83627hf.c @@ -130,17 +130,23 @@ superio_select(struct w83627hf_sio_data *sio, int ld) outb(ld, sio->sioaddr + 1); } -static inline void +static inline int superio_enter(struct w83627hf_sio_data *sio) { + if (!request_muxed_region(sio->sioaddr, 2, DRVNAME)) + return -EBUSY; + outb(0x87, sio->sioaddr); outb(0x87, sio->sioaddr); + + return 0; } static inline void superio_exit(struct w83627hf_sio_data *sio) { outb(0xAA, sio->sioaddr); + release_region(sio->sioaddr, 2); } #define W627_DEVID 0x52 @@ -1275,7 +1281,7 @@ static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); static int __init w83627hf_find(int sioaddr, unsigned short *addr, struct w83627hf_sio_data *sio_data) { - int err = -ENODEV; + int err; u16 val; static __initconst char *const names[] = { @@ -1287,7 +1293,11 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr, }; sio_data->sioaddr = sioaddr; - superio_enter(sio_data); + err = superio_enter(sio_data); + if (err) + return err; + + err = -ENODEV; val = force_id ? force_id : superio_inb(sio_data, DEVID); switch (val) { case W627_DEVID: @@ -1641,9 +1651,21 @@ static int w83627thf_read_gpio5(struct platform_device *pdev) struct w83627hf_sio_data *sio_data = dev_get_platdata(&pdev->dev); int res = 0xff, sel; - superio_enter(sio_data); + if (superio_enter(sio_data)) { + /* + * Some other driver reserved the address space for itself. + * We don't want to fail driver instantiation because of that, + * so display a warning and keep going. + */ + dev_warn(&pdev->dev, + "Can not read VID data: Failed to enable SuperIO access\n"); + return res; + } + superio_select(sio_data, W83627HF_LD_GPIO5); + res = 0xff; + /* Make sure these GPIO pins are enabled */ if (!(superio_inb(sio_data, W83627THF_GPIO5_EN) & (1<<3))) { dev_dbg(&pdev->dev, "GPIO5 disabled, no VID function\n"); @@ -1674,7 +1696,17 @@ static int w83687thf_read_vid(struct platform_device *pdev) struct w83627hf_sio_data *sio_data = dev_get_platdata(&pdev->dev); int res = 0xff; - superio_enter(sio_data); + if (superio_enter(sio_data)) { + /* + * Some other driver reserved the address space for itself. + * We don't want to fail driver instantiation because of that, + * so display a warning and keep going. + */ + dev_warn(&pdev->dev, + "Can not read VID data: Failed to enable SuperIO access\n"); + return res; + } + superio_select(sio_data, W83627HF_LD_HWM); /* Make sure these GPIO pins are enabled */ -- 2.20.1