Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp275177ybi; Wed, 29 May 2019 21:10:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqyiEn1BDhZfM6eY73PcoPNDLCj4gi7ppzdevwuzwLzd1HmlGOkiHqg2Q/oV8TV+VJA2QC9j X-Received: by 2002:a17:90a:a593:: with SMTP id b19mr1537116pjq.31.1559189434065; Wed, 29 May 2019 21:10:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559189434; cv=none; d=google.com; s=arc-20160816; b=KzXZMLYIQHO79gIPmigZlwEd6O+aElou3m5ileuv4qLZy6Uw+1b8o91fVyoDtFU+y6 YoxJ6kpg3b/d46Zhj5pXYyGfeelV/lpf3EanMtrO0WW9b9KEeE5EQYo+05n6pfe9KbS7 AFmDPK8yX3SPCF4Iuo3Bk347ADfmkOsrG/ufjD4aSK8MowcNSPuBncuT51q6uoY3glXa 2+s5hL3yuxUYBWFVsZFm4eS+m8MQjJ21uKu73De4HlYZP4+SctA9A2wMVHxGvWeQA1B3 rhFbglCvcuRHEIihagh9ZIFl9EMTvrmVbLGxeYeh05fLgCdDOb3dZC5l9yVWaALpHu3a zdog== 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=hFoRbVVb+irD7beCLaRYYt0DorekiiGJxMk4DhSxk8Q=; b=n8lbrXBY+XMX65RnpKwsHviZozcKkfhwflE033iyUPlePwB4NThBaqXbCHEEztKVSz SIJrPgkXT8IURIKnCYO3WVuQ10rbUf5Flri4jbjFOu9oVnVA0FlBCwS2J9I3O80o8tHz nODn99mgn/0IX257/VMQjFOmZUNALftj+bH0JHGIX0ASTL1EyJRw/G2MfXFei+flNawg hmShWnxQ5YfxbOpT3FmzG3sOkl5/8dKflfRM00StPPsnMjmGK9lYMLK/pf+3rLOjrAn5 0lWhogaGLhJMwEjpQo1fJAIp4fedWdWobJ3ApF+ZEYiXabOU96cvnA7Yr4VFqvromIky 7KHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F7whppBH; 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 14si2372935pfw.143.2019.05.29.21.10.17; Wed, 29 May 2019 21:10:34 -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=F7whppBH; 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 S1727182AbfE3EH5 (ORCPT + 99 others); Thu, 30 May 2019 00:07:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:46480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731094AbfE3DRY (ORCPT ); Wed, 29 May 2019 23:17:24 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (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 46C4624469; Thu, 30 May 2019 03:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186244; bh=CLNvXd+bHDw5o9XKvwpl1iSa3ZtiTufxn3+Q/WLnUZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F7whppBHKKiY7S0mOt61/cK3ODGQbxTud6ntwq0EbEUb0BtHTaAJdUZ8SQruvEsYa 50FMCuwvclDtTBGh/sIliBazkKZoFRwINTjWS0LH9Mm061FmMS8a4k9WNGn4x7f0Hd 53Wjiej4ufLIpFpj9STZLsy9S0deJAfdCMUrVZ4U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kefeng Wang , John Garry , Guenter Roeck , Sasha Levin Subject: [PATCH 4.19 158/276] hwmon: (smsc47m1) Use request_muxed_region for Super-IO accesses Date: Wed, 29 May 2019 20:05:16 -0700 Message-Id: <20190530030535.394945616@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@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 d6410408ad2a798c4cc685252c1baa713be0ad69 ] 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: 8d5d45fb1468 ("I2C: Move hwmon drivers (2/3)") Reported-by: Kefeng Wang Reported-by: John Garry Cc: John Garry Acked-by: John Garry Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/smsc47m1.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c index c7b6a425e2c02..5eeac9853d0ae 100644 --- a/drivers/hwmon/smsc47m1.c +++ b/drivers/hwmon/smsc47m1.c @@ -73,16 +73,21 @@ superio_inb(int reg) /* logical device for fans is 0x0A */ #define superio_select() superio_outb(0x07, 0x0A) -static inline void +static inline int superio_enter(void) { + if (!request_muxed_region(REG, 2, DRVNAME)) + return -EBUSY; + outb(0x55, REG); + return 0; } static inline void superio_exit(void) { outb(0xAA, REG); + release_region(REG, 2); } #define SUPERIO_REG_ACT 0x30 @@ -531,8 +536,12 @@ static int __init smsc47m1_find(struct smsc47m1_sio_data *sio_data) { u8 val; unsigned short addr; + int err; + + err = superio_enter(); + if (err) + return err; - superio_enter(); val = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID); /* @@ -608,13 +617,14 @@ static int __init smsc47m1_find(struct smsc47m1_sio_data *sio_data) static void smsc47m1_restore(const struct smsc47m1_sio_data *sio_data) { if ((sio_data->activate & 0x01) == 0) { - superio_enter(); - superio_select(); - - pr_info("Disabling device\n"); - superio_outb(SUPERIO_REG_ACT, sio_data->activate); - - superio_exit(); + if (!superio_enter()) { + superio_select(); + pr_info("Disabling device\n"); + superio_outb(SUPERIO_REG_ACT, sio_data->activate); + superio_exit(); + } else { + pr_warn("Failed to disable device\n"); + } } } -- 2.20.1