From patchwork Wed Sep 4 17:54:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 172949 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp1046782ocp; Wed, 4 Sep 2019 11:09:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxh1DN3nlmdr0EEa65xgP+yiMRSjm0ZNuhanByqHmIYixrv3gCukd9Hb8IaXQ3Uh/c2KHh9 X-Received: by 2002:a17:902:4303:: with SMTP id i3mr43851117pld.30.1567620459625; Wed, 04 Sep 2019 11:07:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620459; cv=none; d=google.com; s=arc-20160816; b=CQFG+6GPGzDdc1NizvJnSRAWPExodTrk0P/TeH+YQQTHMZo32kSErFgHoSJFSM3w0z aAxDVG93BPy/Br6jA7C18zRJuWk62Q/9lUuBsi2mMmjyG6ByzFNhCr7eDDKaT/LejItm asWdD2STsgoUq3AVaTpJ0nfTCDD6t+GG652fQMMzuPLLe/MDxaaxAQ6Ajma2gK+7wGD1 p7jFb8qTSzWU3ddunbauh4w4MquEAZC1altcWNWo+jokNSx6+f02eXcfx5gYkUtsg8iR F5NCf0WidRhKcdt8dut8ewhy/qlPn2IJUSwTdwQ7o2+C2BwWHezw4zVfRpUZeoD8/b4U /5JQ== 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=WsVCmhbIAfzBiSkhDfbATs/v+o1QQnEXOMIRluvJSJw=; b=ABmdzilKnL+rkWug4ldsp9pCrkZ8RmdYqwTkCL/H1ypQRyXlZ8sXq0SHDyVrIM37n2 lnD1bRFayN5mtMiNa1X9J/HFmIRiqrdnck5ZBTqqB121BnhVPfSf6ga2q34/9BAUAI1r 4ZNnhmjYgw5DSkvJY8oC2P0UFBr90hHqkPxCQ2ll97bE8ErYCIJ/hLY1EoFYt/EQwuHy lh/gTogIEiTLbVcLnYyIjYvjfcfsraU4/PJ2tuCzQM+3+EIiyEqVdpvewidk+JbfN11W RGiJclKdiLnmsvU0MNVqiryD5mSCIavSbxTzTahtJWmjE+2iTEj3Y+k1sU+qGm3Gqr0c IliA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MOI1rfJy; 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 b19si2834426pjo.55.2019.09.04.11.07.39; Wed, 04 Sep 2019 11:07: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=MOI1rfJy; 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 S2389508AbfIDSHi (ORCPT + 28 others); Wed, 4 Sep 2019 14:07:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:50096 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389470AbfIDSHf (ORCPT ); Wed, 4 Sep 2019 14:07:35 -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 922F12087E; Wed, 4 Sep 2019 18:07:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620454; bh=DAi0C6swFcMcd//mMOcVxSAobHTZG8k4cKETahqWwl8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MOI1rfJyY+/Ag64L+eiKpHqhQmDct6gIiILf74EpouDGig3I4OFkaLNubHT1SZrKX lB2VqxkntpGUiOf2CZ2ylNQsc7/Ytm1Kd3R7ueAhkgUedyXPniwnCInCC9orqIPbS7 LPyEExZMMRXWfH58h5jgWXshkjJpHlqeej9uVwhE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Philip Langdale , Ulf Hansson , Manuel Presnitz Subject: [PATCH 4.19 64/93] mmc: core: Fix init of SD cards reporting an invalid VDD range Date: Wed, 4 Sep 2019 19:54:06 +0200 Message-Id: <20190904175308.500855452@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175302.845828956@linuxfoundation.org> References: <20190904175302.845828956@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ulf Hansson commit 72741084d903e65e121c27bd29494d941729d4a1 upstream. The OCR register defines the supported range of VDD voltages for SD cards. However, it has turned out that some SD cards reports an invalid voltage range, for example having bit7 set. When a host supports MMC_CAP2_FULL_PWR_CYCLE and some of the voltages from the invalid VDD range, this triggers the core to run a power cycle of the card to try to initialize it at the lowest common supported voltage. Obviously this fails, since the card can't support it. Let's fix this problem, by clearing invalid bits from the read OCR register for SD cards, before proceeding with the VDD voltage negotiation. Cc: stable@vger.kernel.org Reported-by: Philip Langdale Signed-off-by: Ulf Hansson Reviewed-by: Philip Langdale Tested-by: Philip Langdale Tested-by: Manuel Presnitz Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/core/sd.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -1277,6 +1277,12 @@ int mmc_attach_sd(struct mmc_host *host) goto err; } + /* + * Some SD cards claims an out of spec VDD voltage range. Let's treat + * these bits as being in-valid and especially also bit7. + */ + ocr &= ~0x7FFF; + rocr = mmc_select_voltage(host, ocr); /* From patchwork Wed Sep 4 17:54:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 172945 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp1044699ocp; Wed, 4 Sep 2019 11:07:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIMK1eMoxiPwE7AyjSJtP88BX1HnUz6mCi/ew46ttRiPeQDYf7tx5lnP9z7WIaP0pbE/P6 X-Received: by 2002:a65:6294:: with SMTP id f20mr37263465pgv.349.1567620474943; Wed, 04 Sep 2019 11:07:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620474; cv=none; d=google.com; s=arc-20160816; b=iAmk/tgYMDQ1LsqbJDqUv2Mw2nQIWB3aiqI1a/ZnymW3BmIHG9wuY/Pn8T9cTQjRM3 0fDDv1OightngXIQEvuAoc214r9sOn7te++0ADHB+uRsQ2OMqR2cyT6TdlwCM2GuLNwI e9wUo7zGSic9ebF0yd6b7O41VmT75LwZKLokupDn1UjCZom2cu6Dtan31PPvp9ww2HQc fB0A+F8xDqmZd/1iIP7FR2B8mdkTfxFjELsj6yfo2KLtYYOzhXhJFjS8wiXvq/kC5cPq NZ5jXshuwOZe8GDepJZXhivmMi/q8XJoUp/hXEVy/B7ggV4+kQUqKIhyZjvMg727FX5N e0+A== 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=dSglE/DDokgdMKJ1GMdt6siYkdDUnpLEvwTlrPGy7QA=; b=px3MigWiLDHjVA6Mzx/zSNscmiwHKnJXpuN70xwPEtctPEDm4mSNA3tNY7CE76sE+p CiiNN1RInWXEjSRZhVSNkV7DLIR7AWlgDj9tPvV7VKL3EfNcyHhoFQtBGs3+6czbrVWB xWpAXYpaJ10zeCFttMHoJL07jJDKBiWGqtaqE514spxFv7U3x/eJTpxmr0s4Le5HJjqp x8Vi6E5C8d2XUjQIGHwsF485FKOwQCQj33fRcIgyemAMtkMAThdCgotqnUZfkdfxuxlZ Wh9RqzIYa9cri6yvTaJeliaB4vU/eScHnNYZd9Tp2d+6RlR2mrwHGUuPqchB1F+FN685 Q2rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qik2EbBD; 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 cm21si2944150pjb.63.2019.09.04.11.07.54; Wed, 04 Sep 2019 11:07:54 -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=qik2EbBD; 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 S2389091AbfIDSHx (ORCPT + 28 others); Wed, 4 Sep 2019 14:07:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:50444 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389673AbfIDSHv (ORCPT ); Wed, 4 Sep 2019 14:07:51 -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 9611722CEA; Wed, 4 Sep 2019 18:07:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620470; bh=0JTnuWsTelDkywrJ0M1VQsfCLhs1bVpfAngi0Bt8z9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qik2EbBDcfB8OyGfrBcU4zWn1PLWAp6oHaGib4Q/17J/MKAIIRZZoSO601xUNWCb6 UsHJ8DCipxRz9Rw5fIoNTZZWkLzDgX9GfWOHTahxo8LTkbSa48ClpCzlcR+tH98zuz dFc+48F8qmibVyPlPtYjvUy7lyhWImaotGQl/i18= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Garry , Wei Xu Subject: [PATCH 4.19 70/93] lib: logic_pio: Fix RCU usage Date: Wed, 4 Sep 2019 19:54:12 +0200 Message-Id: <20190904175309.102352926@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175302.845828956@linuxfoundation.org> References: <20190904175302.845828956@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Garry commit 06709e81c668f5f56c65b806895b278517bd44e0 upstream. The traversing of io_range_list with list_for_each_entry_rcu() is not properly protected by rcu_read_lock() and rcu_read_unlock(), so add them. These functions mark the critical section scope where the list is protected for the reader, it cannot be "reclaimed". Any updater - in this case, the logical PIO registration functions - cannot update the list until the reader exits this critical section. In addition, the list traversing used in logic_pio_register_range() does not need to use the rcu variant. This is because we are already using io_range_mutex to guarantee mutual exclusion from mutating the list. Cc: stable@vger.kernel.org Fixes: 031e3601869c ("lib: Add generic PIO mapping method") Signed-off-by: John Garry Signed-off-by: Wei Xu Signed-off-by: Greg Kroah-Hartman --- lib/logic_pio.c | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -46,7 +46,7 @@ int logic_pio_register_range(struct logi end = new_range->hw_start + new_range->size; mutex_lock(&io_range_mutex); - list_for_each_entry_rcu(range, &io_range_list, list) { + list_for_each_entry(range, &io_range_list, list) { if (range->fwnode == new_range->fwnode) { /* range already there */ goto end_register; @@ -108,26 +108,38 @@ end_register: */ struct logic_pio_hwaddr *find_io_range_by_fwnode(struct fwnode_handle *fwnode) { - struct logic_pio_hwaddr *range; + struct logic_pio_hwaddr *range, *found_range = NULL; + rcu_read_lock(); list_for_each_entry_rcu(range, &io_range_list, list) { - if (range->fwnode == fwnode) - return range; + if (range->fwnode == fwnode) { + found_range = range; + break; + } } - return NULL; + rcu_read_unlock(); + + return found_range; } /* Return a registered range given an input PIO token */ static struct logic_pio_hwaddr *find_io_range(unsigned long pio) { - struct logic_pio_hwaddr *range; + struct logic_pio_hwaddr *range, *found_range = NULL; + rcu_read_lock(); list_for_each_entry_rcu(range, &io_range_list, list) { - if (in_range(pio, range->io_start, range->size)) - return range; + if (in_range(pio, range->io_start, range->size)) { + found_range = range; + break; + } } - pr_err("PIO entry token %lx invalid\n", pio); - return NULL; + rcu_read_unlock(); + + if (!found_range) + pr_err("PIO entry token 0x%lx invalid\n", pio); + + return found_range; } /** @@ -180,14 +192,23 @@ unsigned long logic_pio_trans_cpuaddr(re { struct logic_pio_hwaddr *range; + rcu_read_lock(); list_for_each_entry_rcu(range, &io_range_list, list) { if (range->flags != LOGIC_PIO_CPU_MMIO) continue; - if (in_range(addr, range->hw_start, range->size)) - return addr - range->hw_start + range->io_start; + if (in_range(addr, range->hw_start, range->size)) { + unsigned long cpuaddr; + + cpuaddr = addr - range->hw_start + range->io_start; + + rcu_read_unlock(); + return cpuaddr; + } } - pr_err("addr %llx not registered in io_range_list\n", - (unsigned long long) addr); + rcu_read_unlock(); + + pr_err("addr %pa not registered in io_range_list\n", &addr); + return ~0UL; } From patchwork Wed Sep 4 17:54:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 172946 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp1044837ocp; Wed, 4 Sep 2019 11:08:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUrGUdmKnFsrpvr8B+eqmWhIOVgpVcUvm0KwrhGIq6XioGLWj83dJhTkxL6nLhPrZ1vNNI X-Received: by 2002:a65:43c2:: with SMTP id n2mr36521121pgp.110.1567620482014; Wed, 04 Sep 2019 11:08:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620482; cv=none; d=google.com; s=arc-20160816; b=T2qDaLxNHRLy3MWVo5VFIaKQ9Wfnmp01ehE5i1WikMMgLJIG+6IhwXMoqBNT3V+on9 uG0RNrwpmoToDcE+FW0rnjda8tSmeX0xChbVvt8hspyMz7f2S1E5ujlvcvv4gywg1AO4 /5Q3lNt3C0hmtsIdb7q6vZoWPCHtW09lZ7nSIHGYNTZnAYFO1inqfdkwHtyhwoFTxiZk ElQy/Czp3yMGf0sSOlFtWHp6Wb7WSfpzjnWwPHtBRaIcRjtOkt5Lgd+GpeJun1gP9xl1 rhyUGYNSsjxv8RV92zmF2owutHuJCDVL4IaQXWJ0LjEGgvUHrZbJjUSeB/EdVuwruM5Z x8+w== 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=KrV8T0HaWbpbELilfw7x90MNqYHtZaqDNT2nMNqDKmg=; b=AcQ8J4tNDyaD+wgbwWPVxqMVME/8u7LAIMXfPPcODnCX71LpJSlu3McpucYRSA7KFr EZruDb+ECsyRzJcQgHNh6mXVgqBytDgQ3ttqy/4pVCAwCsj9rR6Xl0yzyxb1028XZwTO iy05cDocJ1IWn0vswJicQLsbMYxR+yANt4GKdWCTMVj2K6zsKEDJ51k3U6mrLrJRFkz2 KrdZF68Q8Pp081YD0bAqdEM8Fv/3yQxvdCyauI5mJ99voIi4awMf7zPsisGvwLHMOfR0 r9mlvnNQr9EwYE9hBzG6awkiI0U8dQ3i0TiV/RivllMNZ8OONcmqpOsw8qzQDWpOLIFX v14Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=onyeQLt+; 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 v186si16946265pgd.358.2019.09.04.11.08.01; Wed, 04 Sep 2019 11:08:02 -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=onyeQLt+; 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 S2389706AbfIDSIA (ORCPT + 28 others); Wed, 4 Sep 2019 14:08:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:50640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389694AbfIDSH7 (ORCPT ); Wed, 4 Sep 2019 14:07:59 -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 8B1452087E; Wed, 4 Sep 2019 18:07:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620478; bh=izBRRnXiw9mOfutHNB06OnVP5gsPFMTfZ8E+HUYKFVE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=onyeQLt+fcsrXO2eMudSM0VClOOuMd+funeV1xiWmqkoHo7HXuARrrq5uJ4sw1xE9 L+utJs/LpHBnaXg8/PHf3auyR1naQJ2oJY774tMHwvHFNuHCFHkH3e2PskFQpAWSEY m/ZousKqRhV0c3VzlY0NeYJTzajaSH+AWHhZzLvE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Garry , Wei Xu Subject: [PATCH 4.19 72/93] lib: logic_pio: Add logic_pio_unregister_range() Date: Wed, 4 Sep 2019 19:54:14 +0200 Message-Id: <20190904175309.300889191@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175302.845828956@linuxfoundation.org> References: <20190904175302.845828956@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Garry commit b884e2de2afc68ce30f7093747378ef972dde253 upstream. Add a function to unregister a logical PIO range. Logical PIO space can still be leaked when unregistering certain LOGIC_PIO_CPU_MMIO regions, but this acceptable for now since there are no callers to unregister LOGIC_PIO_CPU_MMIO regions, and the logical PIO region allocation scheme would need significant work to improve this. Cc: stable@vger.kernel.org Signed-off-by: John Garry Signed-off-by: Wei Xu Signed-off-by: Greg Kroah-Hartman --- include/linux/logic_pio.h | 1 + lib/logic_pio.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) --- a/include/linux/logic_pio.h +++ b/include/linux/logic_pio.h @@ -117,6 +117,7 @@ struct logic_pio_hwaddr *find_io_range_b unsigned long logic_pio_trans_hwaddr(struct fwnode_handle *fwnode, resource_size_t hw_addr, resource_size_t size); int logic_pio_register_range(struct logic_pio_hwaddr *newrange); +void logic_pio_unregister_range(struct logic_pio_hwaddr *range); resource_size_t logic_pio_to_hwaddr(unsigned long pio); unsigned long logic_pio_trans_cpuaddr(resource_size_t hw_addr); --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -99,6 +99,20 @@ end_register: } /** + * logic_pio_unregister_range - unregister a logical PIO range for a host + * @range: pointer to the IO range which has been already registered. + * + * Unregister a previously-registered IO range node. + */ +void logic_pio_unregister_range(struct logic_pio_hwaddr *range) +{ + mutex_lock(&io_range_mutex); + list_del_rcu(&range->list); + mutex_unlock(&io_range_mutex); + synchronize_rcu(); +} + +/** * find_io_range_by_fwnode - find logical PIO range for given FW node * @fwnode: FW node handle associated with logical PIO range * From patchwork Wed Sep 4 17:54:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 172947 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp1045096ocp; Wed, 4 Sep 2019 11:08:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyvJMOoQJ7cCiyMJJ8GBpozGEFozftlprbdZtYnnmqEdBuOduF97BSNBLi0N5QhqZ+Sgfog X-Received: by 2002:aa7:9e04:: with SMTP id y4mr47117100pfq.18.1567620493544; Wed, 04 Sep 2019 11:08:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620493; cv=none; d=google.com; s=arc-20160816; b=Ia+aAIcv8l6SF4ePMLKmOEt03bqNH8HCwyIcdPn1tJQHXV9nn8yhKjZLI2MxN2o/dx ER4RnrNuxeSfPPb1bQCf3Sd6e0DETSZ6DPGjUllLYWrve+6ncHt42DHfmq8bWrYOBTGM gsiBRS9pPxilv8EPB5sy+rrqY1tXi5sH1JcOjsc97a+1hHQdQmcpBbF97AmF1OoMuE9x n/8rFWLI4NKr2GejP/cMfCUjnZIwOcueIo61rLOTCEMU9Mpe0dGNeDSri5PSBEwIjvhB 22oSgrRAAy0R2Qt13k9FOfGcsQMCfZpDmwmt9l+LEDiq8NZ/m9ctsMtGwmKHzS4ewkbH OBag== 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=CKu4w6/0CNsugLOOOLmzEux0cAf0NqIkTu290+0pKac=; b=YJE0vQdWKmcnj38bTf9eDnK74qsX6eiNEs5gwqPMCm8aTP7OBHTnQOc3ywf/V+Akdd ncA48rUlZXQSXTNZUX3DrmU01NDYrlCzzS9+W4SZFyLyH0O179bwkV9GOSShniCV1vZs M/9Y810alUe4baQcwbUdYQruNXr4WZAU4vlXSOiNANSKuH4TeGjNRRqapc3xQ3Uuqvq6 +UX8UhdI4c0/p2Zm9UL6dMnKurBytOm1m1tpLlv27lnTawjONrBF9iBU0GjKNIyMfgMS rwcX9i1IDewMNCOE3Zpei3HmAzU0T4Vp+PdyMpR6ov8nkQ6F+hmiknNKwqYnQw3DLqO2 Fv8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Q1ru0Ivw; 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 u65si14818025pfu.160.2019.09.04.11.08.13; Wed, 04 Sep 2019 11:08:13 -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=Q1ru0Ivw; 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 S2389737AbfIDSIM (ORCPT + 28 others); Wed, 4 Sep 2019 14:08:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:50856 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388808AbfIDSIJ (ORCPT ); Wed, 4 Sep 2019 14:08:09 -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 3A5F320870; Wed, 4 Sep 2019 18:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620488; bh=A6jqfQt1fU2Vf6DkHcpoLkmMml53rNnwKzLsF4280cs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q1ru0Ivwjb31MqRzaO5nRNgD3x5U1NqwJ3f8oOgePsBv6c32YukftHAoMczdqnVap CpjLNg+FEhRbDiT88xIh4qs1xOEVVU5f/GGcbU+lt2NX1EMcxstFDZJzCueQRl2nM0 GlSs1HzK8A/3VQfMQeqGmxVO/vwGPH68AmJhRKxc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Garry , Wei Xu Subject: [PATCH 4.19 76/93] bus: hisi_lpc: Unregister logical PIO range to avoid potential use-after-free Date: Wed, 4 Sep 2019 19:54:18 +0200 Message-Id: <20190904175309.655425948@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175302.845828956@linuxfoundation.org> References: <20190904175302.845828956@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Garry commit 1b15a5632a809ab57d403fd972ca68785363b654 upstream. If, after registering a logical PIO range, the driver probe later fails, the logical PIO range memory will be released automatically. This causes an issue, in that the logical PIO range is not unregistered and the released range memory may be later referenced. Fix by unregistering the logical PIO range. And since we now unregister the logical PIO range for probe failure, avoid the special ordering of setting logical PIO range ops, which was the previous (poor) attempt at a safeguard against this. Cc: stable@vger.kernel.org Fixes: adf38bb0b595 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings") Signed-off-by: John Garry Signed-off-by: Wei Xu Signed-off-by: Greg Kroah-Hartman --- drivers/bus/hisi_lpc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/drivers/bus/hisi_lpc.c +++ b/drivers/bus/hisi_lpc.c @@ -607,24 +607,25 @@ static int hisi_lpc_probe(struct platfor range->fwnode = dev->fwnode; range->flags = LOGIC_PIO_INDIRECT; range->size = PIO_INDIRECT_SIZE; + range->hostdata = lpcdev; + range->ops = &hisi_lpc_ops; + lpcdev->io_host = range; ret = logic_pio_register_range(range); if (ret) { dev_err(dev, "register IO range failed (%d)!\n", ret); return ret; } - lpcdev->io_host = range; /* register the LPC host PIO resources */ if (acpi_device) ret = hisi_lpc_acpi_probe(dev); else ret = of_platform_populate(dev->of_node, NULL, NULL, dev); - if (ret) + if (ret) { + logic_pio_unregister_range(range); return ret; - - lpcdev->io_host->hostdata = lpcdev; - lpcdev->io_host->ops = &hisi_lpc_ops; + } io_end = lpcdev->io_host->io_start + lpcdev->io_host->size; dev_info(dev, "registered range [%pa - %pa]\n",