Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1759172pxb; Wed, 9 Feb 2022 04:01:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzOUkoCNXt7Ic3JidHnvk7h7Kj2sINUMly0GguhGOgaMt6jCxx3ayd4y90D96pZsMLetaTl X-Received: by 2002:a17:902:b189:: with SMTP id s9mr1896290plr.112.1644408091552; Wed, 09 Feb 2022 04:01:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644408091; cv=none; d=google.com; s=arc-20160816; b=iJDEBeH5bvXfzdhfKBwbz5nOcL0R4tQryMj8OuoPM7ozTodpXJNr176h5Gf+pShHcs Hy5qIiQlUURutGePx8jM+VFTcb6oWf+/Fou7WQPtpu5LnKmgJa0SMEUgA1VaLmgGXb4N UDGWjFc58tBbGu4YMP3FXu/L1WXuyATJ7rya7pcp7yCJMpFqS1QKM4p0Xrro3GjY6iUw O/cp+58450tA03KBALjXYunSPvCwszqej3dFtfakmkzK9QBAZHGANjqY/VdT1kOJ+idZ aD0c/cni6HuPpWrA4rUcWUfvqxbE1xcsy3UDypzabCkpnnR63IC9ZfbNAdQlXJj1s36e XyCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vwaNu6qQxChzhM66H8tt8h3+Mr41ei+1TqThVGHEx2Y=; b=Qh81bnkQevlzyMu4Q6r5YQWL4oGcsU3L2Dlri3tK+C+2AD4ZSPsYw6NeFdZL8wX6iC kVOq7UkdYvmwo3oQIcby8kI7QlfXTbJsXQ/DkGTWMJALE8WxAYdT5FMQV48dEQzcSYxc UUdQMCZ/hz8ckDnZHRkPrv2C0/t8A+I0DoACYUTpFGRqSlXYSzMlCgd0h608tgnwY4c2 URDY+L91/RU49CDU0M02LestbpyVxofOfYEpB+PPvQpEWE34g+uVFLWKQQzLqqYEKxsD +YZtGU/dI3H28jfjXlamQmMCeL/47/npkuyOJrD3MbYzpCpScPOdME3DB6ZfTTtmrnC0 99jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ETyhh2uM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id f22si16315979pfj.348.2022.02.09.04.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 04:01:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ETyhh2uM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A48C4E0F1D5E; Wed, 9 Feb 2022 02:04:07 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356637AbiBGLUD (ORCPT + 99 others); Mon, 7 Feb 2022 06:20:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377080AbiBGLPW (ORCPT ); Mon, 7 Feb 2022 06:15:22 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B4F0C0401C1; Mon, 7 Feb 2022 03:15:00 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BA05DB811AF; Mon, 7 Feb 2022 11:14:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3EEFC004E1; Mon, 7 Feb 2022 11:14:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644232497; bh=MT4sNF0PfxcIg6PS6y3Pd/xe1QUKigz4w0dUAF1+YxE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ETyhh2uMGQ8WDmBAG8dpTNh0XexMnwjiVzQziIZVq3YB4RFzWezVZgQ1waWoNDeYt Z0rrVcNNuz0jbh7CRpmdqi1ctAHm9foDEiYQbt/69e2aWuaahFC6ADIB6vHwf8jHmk VecW0eKw2GtbpGOnGeM6ATDOZ2rQltImHgXEMwRE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robert Hancock Subject: [PATCH 4.19 09/86] serial: 8250: of: Fix mapped region size when using reg-offset property Date: Mon, 7 Feb 2022 12:05:32 +0100 Message-Id: <20220207103757.862574812@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103757.550973048@linuxfoundation.org> References: <20220207103757.550973048@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robert Hancock commit d06b1cf28297e27127d3da54753a3a01a2fa2f28 upstream. 8250_of supports a reg-offset property which is intended to handle cases where the device registers start at an offset inside the region of memory allocated to the device. The Xilinx 16550 UART, for which this support was initially added, requires this. However, the code did not adjust the overall size of the mapped region accordingly, causing the driver to request an area of memory past the end of the device's allocation. For example, if the UART was allocated an address of 0xb0130000, size of 0x10000 and reg-offset of 0x1000 in the device tree, the region of memory reserved was b0131000-b0140fff, which caused the driver for the region starting at b0140000 to fail to probe. Fix this by subtracting reg-offset from the mapped region size. Fixes: b912b5e2cfb3 ([POWERPC] Xilinx: of_serial support for Xilinx uart 16550.) Cc: stable Signed-off-by: Robert Hancock Link: https://lore.kernel.org/r/20220112194214.881844-1-robert.hancock@calian.com Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/8250/8250_of.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- a/drivers/tty/serial/8250/8250_of.c +++ b/drivers/tty/serial/8250/8250_of.c @@ -104,8 +104,17 @@ static int of_platform_serial_setup(stru port->mapsize = resource_size(&resource); /* Check for shifted address mapping */ - if (of_property_read_u32(np, "reg-offset", &prop) == 0) + if (of_property_read_u32(np, "reg-offset", &prop) == 0) { + if (prop >= port->mapsize) { + dev_warn(&ofdev->dev, "reg-offset %u exceeds region size %pa\n", + prop, &port->mapsize); + ret = -EINVAL; + goto err_unprepare; + } + port->mapbase += prop; + port->mapsize -= prop; + } port->iotype = UPIO_MEM; if (of_property_read_u32(np, "reg-io-width", &prop) == 0) {