From patchwork Tue Apr 11 08:33:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 81804 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2422191vqo; Tue, 11 Apr 2023 01:49:18 -0700 (PDT) X-Google-Smtp-Source: AKy350aNYPNaaTtyOVDT5VqnSXuh6SWABaVHeawXqAf6s8WLQY2x+DXyPpIWzZNUKcAHPqg0wf7u X-Received: by 2002:a17:90a:aa82:b0:246:9ef5:3c45 with SMTP id l2-20020a17090aaa8200b002469ef53c45mr2737780pjq.13.1681202958613; Tue, 11 Apr 2023 01:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681202958; cv=none; d=google.com; s=arc-20160816; b=lrDUSYe9BjltRUQUnAesFkBfHrxl4itB8Fyf0Rim4sBZPwvB//lKwW2w0hGHHx+z0+ BL4H+29kYDfYUWqh9MRyBN164oArsFFk7hckN+xDz5KSTIJs/dCCtmmEyDAroBEY1h7z lpqQrK7TwWCMcAKXiAizaqZ9tvSy2ms+vOBcYB4gSUZ5BArxclIVSwUWN+VLRfhKWpR2 qO1GKZ6WcRWSVn825L78RUrF5mTYGTlMpEP0rThryzrK3xBqE07KkjWh9SIXxYkJhK+S rChlBK6zTwABN4P4qk7tb7ch1H486+RTNGF5da6mOBNIFEyy1mRZ/JcvgiJAI5j/4UvH 5k9Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Y/F/1PUJwUX6hCcJ6JDKSJ9tj5PmDrf32kZ6wJpW/Zo=; b=aWpZW6cSrT1LifN0Z1cAo4dnQ3eLxmbtVpmL+dq0GswggYVOiHgFRUCPKBw7Rxwi94 6K0XvgZAqZ2JSMSZAE2GJq3TgE2q+JPX+bGWBvuD8CuR77WSHaxA3wtgKycfG5vrhWnI nATlL7KORtZMsYNwZtuuFInYWPYMHDYLYwbLryxhsygyUVufOFUHgzaL5KE2sBfbO9X0 jiwT7w8QKZG6imKY2XpP07Nery2B1P+MzSHbl1gEiGUjh+KOv+5dzegRGceKG4IbiaEA nh4ci0zv0/Pv/Ov7rG2j10E5hWvAc7dopi88JzGTuBFPoKxKsSasBU753NH1zVIiwUiV WIjw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s1-20020a17090ae68100b00237155f2303si12640711pjy.136.2023.04.11.01.49.06; Tue, 11 Apr 2023 01:49:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231129AbjDKIeb (ORCPT + 99 others); Tue, 11 Apr 2023 04:34:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230492AbjDKIe0 (ORCPT ); Tue, 11 Apr 2023 04:34:26 -0400 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 618A210C2 for ; Tue, 11 Apr 2023 01:34:22 -0700 (PDT) Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-94a34a0baf9so174819566b.1 for ; Tue, 11 Apr 2023 01:34:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681202061; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y/F/1PUJwUX6hCcJ6JDKSJ9tj5PmDrf32kZ6wJpW/Zo=; b=cLX5Ci11ngysjh16qUj5iEyNUSKOuzyDt+2Cyax4nBu0gXPbsHNF5Q2TDlTgTWEGfE FnARH6bI4n2DvHbQAV5XB4MLOBst8VluQJCBViiRyDQxSqBs8kM24apxfJe06j/G1CIg 4r59jFT3cQTxx7MCCKhHpCUlhFvvsG2UuAbo2KVxlMW96x2BueQjHJZPY/2p4iy2L4sq q4cgxRFBZEiRV3krl78X1O3sGljz+VbHXbzr0W1DiKwohBt1cAmxc/xXvp5PSwCdQ1Jv hqKf7K8qQ3vIoZPAsSRmWSeaI8Ua1SXslfMDRIZXA9auCUlRAn0FH88OWVGiFFh4WceY BS4g== X-Gm-Message-State: AAQBX9fsiLdSZIObxqL6DeWESUvm5sU/e6abQ3INatuCF3Jw9WWSkZI5 9PCEA3xyWLvTDixfRU40GRs= X-Received: by 2002:a05:6402:10c6:b0:504:b657:4cd8 with SMTP id p6-20020a05640210c600b00504b6574cd8mr3450298edu.31.1681202060806; Tue, 11 Apr 2023 01:34:20 -0700 (PDT) Received: from localhost.localdomain (aftr-82-135-86-174.dynamic.mnet-online.de. [82.135.86.174]) by smtp.googlemail.com with ESMTPSA id v13-20020a50954d000000b004fc649481basm5683178eda.58.2023.04.11.01.34.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 01:34:19 -0700 (PDT) From: Johannes Thumshirn To: Greg Kroah-Hartman Cc: JoseJavier.Rodriguez@duagon.com, Jorge.SanjuanGarcia@duagon.com, linux-kernel@vger.kernel.org, Jorge Sanjuan Garcia , Javier Rodriguez , Johannes Thumshirn Subject: [PATCH 1/3] mcb: Return actual parsed size when reading chameleon table Date: Tue, 11 Apr 2023 10:33:27 +0200 Message-Id: <20230411083329.4506-2-jth@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411083329.4506-1-jth@kernel.org> References: <20230411083329.4506-1-jth@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=0.5 required=5.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762869073274056632?= X-GMAIL-MSGID: =?utf-8?q?1762869073274056632?= From: Rodríguez Barbarin, José Javier The function chameleon_parse_cells() returns the number of cells parsed which has an undetermined size. This return value is only used for error checking but the number of cells is never used. Change return value to be number of bytes parsed to allow for memory management improvements. Co-developed-by: Jorge Sanjuan Garcia Signed-off-by: Jorge Sanjuan Garcia Signed-off-by: Javier Rodriguez Signed-off-by: Johannes Thumshirn --- drivers/mcb/mcb-parse.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/mcb/mcb-parse.c b/drivers/mcb/mcb-parse.c index aa6938da0db8..2aef990f379f 100644 --- a/drivers/mcb/mcb-parse.c +++ b/drivers/mcb/mcb-parse.c @@ -130,7 +130,7 @@ static void chameleon_parse_bar(void __iomem *base, } } -static int chameleon_get_bar(char __iomem **base, phys_addr_t mapbase, +static int chameleon_get_bar(void __iomem **base, phys_addr_t mapbase, struct chameleon_bar **cb) { struct chameleon_bar *c; @@ -179,12 +179,13 @@ int chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase, { struct chameleon_fpga_header *header; struct chameleon_bar *cb; - char __iomem *p = base; + void __iomem *p = base; int num_cells = 0; uint32_t dtype; int bar_count; int ret; u32 hsize; + u32 table_size; hsize = sizeof(struct chameleon_fpga_header); @@ -239,12 +240,16 @@ int chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase, num_cells++; } - if (num_cells == 0) - num_cells = -EINVAL; + if (num_cells == 0) { + ret = -EINVAL; + goto free_bar; + } + table_size = p - base; + pr_debug("%d cell(s) found. Chameleon table size: 0x%04x bytes\n", num_cells, table_size); kfree(cb); kfree(header); - return num_cells; + return table_size; free_bar: kfree(cb); From patchwork Tue Apr 11 08:33:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 81800 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2421167vqo; Tue, 11 Apr 2023 01:46:51 -0700 (PDT) X-Google-Smtp-Source: AKy350b6jBsJQ3GQhjJfvGd+v2eoTlv3Vu30R/cnOgoOHGHphdh/jwIzBl6gAG8YX3wM/ofVEYr3 X-Received: by 2002:a17:90b:3808:b0:246:abd7:16c2 with SMTP id mq8-20020a17090b380800b00246abd716c2mr7819733pjb.47.1681202811265; Tue, 11 Apr 2023 01:46:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681202811; cv=none; d=google.com; s=arc-20160816; b=R0SjjvMtq1PquHcnHTz30FdhY7RM3IcCou9zB6kaoN7qI2IUKFwb6Nt4JNPlzeAV9u IXSS2XMXHx9V7f9IeU9WzdCsexmhc5kPmhvmZN7O0uoyGZB9yvcUlMIksw8X9esXx2ty i24BQ9jhiwdYSrqDLbTFuKZ3buRm6ftuobVuaaMBprUeWitq2ilOAAxcjxjmfEx3U+Ng qHcS00VLoB2Aqas+JtPu6iNP3gV4YpPnyC3uS7O+BOdr5MySdSLTLA8eEzYuXHDsQeSv TyJcDN0X4VyVPdu3ZnwTwHYhjr4BSR8KlK69grC6Ui/Otvwc+1maN51nhqxd0ygb4ydC zXSQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=hkdKJwaH8L7z7o46mK/fJ3bKpTFQDoczm/fDDv32BWM=; b=C5dhgKHnqf0A4MVRBKfzIKi9W+dqFLAYTVKLSj0k26yXQO+sgrH3oju3ld/sVj+cdQ 18RtV/Z9C+rdLWHZXs6fJEVr6aHQKb8MyaCKu9CT0WAFokUP4OuPzse77RgQpZea2ccJ ji/GF4tt93eQWQzlbwszgzOpsk2Frtd/yJlMV7/Vb+IUdSqNT/OZi8KWk9/8ZSWbpotR 9dfkxAWa33Cxnh5VSo8Fv/h6wpG/swZId9E8KniUeqvWMGcZNk+293uj29mcsQZ1nqlq 8QFxe4S8wjJg9JtEVBYXbxHynSujRW9cjRRnFu1rPkig4pTYl/v1SAwAjaaqlDMBYc9K 2vIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h92-20020a17090a29e500b002308ac7a1b0si12576942pjd.117.2023.04.11.01.46.39; Tue, 11 Apr 2023 01:46:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231140AbjDKIed (ORCPT + 99 others); Tue, 11 Apr 2023 04:34:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230509AbjDKIe1 (ORCPT ); Tue, 11 Apr 2023 04:34:27 -0400 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06E2A1701 for ; Tue, 11 Apr 2023 01:34:24 -0700 (PDT) Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5047074939fso15379140a12.1 for ; Tue, 11 Apr 2023 01:34:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681202062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hkdKJwaH8L7z7o46mK/fJ3bKpTFQDoczm/fDDv32BWM=; b=kDBjzCWlO8C/XcnyEYsdgK0t/5VFh2Jgaq7UjvB+Xfq71ZcADJM3snbi7bu4zLuhh0 SCYRWfkQyPCHe36Ts6WuQ7CFIxVT4ZSePqlnJy8AwD8VRubFmUqpazdmYaoi/N53oKUT jFbb4AL3frmxa0oqvR6GeyDPaDnqUCvSO3WgH342IfJD0fsvM5Dc7eBEhwF2th/5/9e2 dV1oXx4Av2sVJx6i0rPkJnqYGcUdrdGpZeY7VP0x3/0WXjrdywtOulpwb1q8OVFN8gys vROsYOJAbTSxreAxh7V+Rbgf7iBdIWyVcpjJXhalvynci8gDB2iL1vM18W77wpmFaAdr XWCg== X-Gm-Message-State: AAQBX9fF17N53lJl6NkpCk6hgl9gzJF/dvtFAf5n7H2r4MJf1RFCuTmo a+HrtM7o8HHNBWoBsG/+RmY= X-Received: by 2002:a05:6402:42d4:b0:502:1d1b:5bef with SMTP id i20-20020a05640242d400b005021d1b5befmr18383779edc.14.1681202062528; Tue, 11 Apr 2023 01:34:22 -0700 (PDT) Received: from localhost.localdomain (aftr-82-135-86-174.dynamic.mnet-online.de. [82.135.86.174]) by smtp.googlemail.com with ESMTPSA id v13-20020a50954d000000b004fc649481basm5683178eda.58.2023.04.11.01.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 01:34:21 -0700 (PDT) From: Johannes Thumshirn To: Greg Kroah-Hartman Cc: JoseJavier.Rodriguez@duagon.com, Jorge.SanjuanGarcia@duagon.com, linux-kernel@vger.kernel.org, Jorge Sanjuan Garcia , Javier Rodriguez , Johannes Thumshirn Subject: [PATCH 2/3] mcb-pci: Reallocate memory region to avoid memory overlapping Date: Tue, 11 Apr 2023 10:33:28 +0200 Message-Id: <20230411083329.4506-3-jth@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411083329.4506-1-jth@kernel.org> References: <20230411083329.4506-1-jth@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=0.5 required=5.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762868918647459320?= X-GMAIL-MSGID: =?utf-8?q?1762868918647459320?= From: Rodríguez Barbarin, José Javier mcb-pci requests a fixed-size memory region to parse the chameleon table, however, if the chameleon table is smaller that the allocated region, it could overlap with the IP Cores' memory regions. After parsing the chameleon table, drop/reallocate the memory region with the actual chameleon table size. Co-developed-by: Jorge Sanjuan Garcia Signed-off-by: Jorge Sanjuan Garcia Signed-off-by: Javier Rodriguez Signed-off-by: Johannes Thumshirn --- drivers/mcb/mcb-pci.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/mcb/mcb-pci.c b/drivers/mcb/mcb-pci.c index dc88232d9af8..53d9202ff9a7 100644 --- a/drivers/mcb/mcb-pci.c +++ b/drivers/mcb/mcb-pci.c @@ -31,7 +31,7 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) { struct resource *res; struct priv *priv; - int ret; + int ret, table_size; unsigned long flags; priv = devm_kzalloc(&pdev->dev, sizeof(struct priv), GFP_KERNEL); @@ -90,7 +90,30 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (ret < 0) goto out_mcb_bus; - dev_dbg(&pdev->dev, "Found %d cells\n", ret); + table_size = ret; + + if (table_size < CHAM_HEADER_SIZE) { + /* Release the previous resources */ + devm_iounmap(&pdev->dev, priv->base); + devm_release_mem_region(&pdev->dev, priv->mapbase, CHAM_HEADER_SIZE); + + /* Then, allocate it again with the actual chameleon table size */ + res = devm_request_mem_region(&pdev->dev, priv->mapbase, + table_size, + KBUILD_MODNAME); + if (!res) { + dev_err(&pdev->dev, "Failed to request PCI memory\n"); + ret = -EBUSY; + goto out_mcb_bus; + } + + priv->base = devm_ioremap(&pdev->dev, priv->mapbase, table_size); + if (!priv->base) { + dev_err(&pdev->dev, "Cannot ioremap\n"); + ret = -ENOMEM; + goto out_mcb_bus; + } + } mcb_bus_add_devices(priv->bus); From patchwork Tue Apr 11 08:33:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 81814 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2425327vqo; Tue, 11 Apr 2023 01:57:10 -0700 (PDT) X-Google-Smtp-Source: AKy350YjNUO1E1nGAhuQpdlHKM0dm58LZ5wbaASEsbvvB+F7hHgcLQsOu+/0sNJRzIVtMtiwIAHt X-Received: by 2002:a17:90b:3a8e:b0:240:d093:7274 with SMTP id om14-20020a17090b3a8e00b00240d0937274mr3264563pjb.14.1681203430531; Tue, 11 Apr 2023 01:57:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681203430; cv=none; d=google.com; s=arc-20160816; b=O5CadZ2FdWAymCFaFaAYLnD68zyCJ55CdHgNHFsbeAuXG+HKVAgqrCk+2lB0PZV/op 69d5kceY506uqpbsgA2LhYVSJ/BAUz+f4tofXVsA6tc4eqJugj1aeygDrvuTCtwh8qRn loMGyuzkFPSMoYhUmD1PFMTD3PNenoGrcaXIjiMuC3v4G4YNyJ52n5BpNufPZ1KJQ7U+ Vv50fF7DQnCqbhBJWJoXvmLkWYuBL1dQbAo0F7qc1g3lbkAXkxen11hbkTQn2/XYVXd1 Zfph4FuvReajLA04M8ZPOiwNFcvFCBiWCK6m23EMnBV8YdARIhXIUH6b9OJgxc3u6tF6 Etbw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=FIQy0z8jTVH7zpmG87sxcsYghwyL6FkUSdX2CbnH7m8=; b=C0oCcrLf/+7Kr2lXzGAjcbtLK2loCdFaCjeRpI1FBvD3c0ombfwwRGLuh9LbMxGLTt pQuH+/WeWrmzxv39Xig/2Xs0oX53xbGhZWcgGhV7GpQBjB4DafWrwVdMWw/58qayswOQ +fNN2+uB12fn9gYT7hdN67M7YZG79SGhU347whAZnq/i+c4tOK+rqpFFcpjYLZf132Df q9iqvMD22njnkMnYoODSB3pGRVYvDas0WH8wFaqw0zLV4ixDTyl2ijnLgS7bo9zcf8OX Wl4ReEwAzHGS4ZBxjlxnPfl2dgNNQGh2q1ruGrRSkcO4VbBs2dj7xEyv83A7tn9dbULV H6jQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h92-20020a17090a29e500b002308ac7a1b0si12576942pjd.117.2023.04.11.01.56.58; Tue, 11 Apr 2023 01:57:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231150AbjDKIef (ORCPT + 99 others); Tue, 11 Apr 2023 04:34:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230448AbjDKIe2 (ORCPT ); Tue, 11 Apr 2023 04:34:28 -0400 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3C082D5A for ; Tue, 11 Apr 2023 01:34:25 -0700 (PDT) Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-50489c6171dso2005129a12.3 for ; Tue, 11 Apr 2023 01:34:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681202064; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FIQy0z8jTVH7zpmG87sxcsYghwyL6FkUSdX2CbnH7m8=; b=DuHQvrn/8Nf7AGWkzoPpopKmBeR2a55nT6ZfggsT2qQtV48yy/cy9SxnYQzW2ib8bO l+Zo5ErASoESd8miPWGvAGnHoU9bryee0XJBjbAK7z4QKQkYO4jLjeEBOnmBrLbK8kJ+ vv2dQHMgucuaT+mXJWANkANvPStSVGQeKml4jhSTHXFfTitCk5Z3kGsAsMkvpXn8mo5S ErPoKIUDsRKUucMhsTkfFrH5CWzeWicgIXwaGrofpQoi80gKqO8rNc18QNmUgOSMgQE3 kZ+dIGQMjCuI44Vj8mqxq4PK1IQsKN3F74PFsuJBqtnEyQ+pZIWBTgXlPFEXYJzAqJyZ BEWQ== X-Gm-Message-State: AAQBX9d5QemXmzOLGIIew7aAiH7tfqXEAIpmWJBfg/5JJEjNxCWCJOJb GH+IX8KGipFO+ZMZDFI+cp4= X-Received: by 2002:aa7:de13:0:b0:502:a700:dc8b with SMTP id h19-20020aa7de13000000b00502a700dc8bmr8410709edv.9.1681202064337; Tue, 11 Apr 2023 01:34:24 -0700 (PDT) Received: from localhost.localdomain (aftr-82-135-86-174.dynamic.mnet-online.de. [82.135.86.174]) by smtp.googlemail.com with ESMTPSA id v13-20020a50954d000000b004fc649481basm5683178eda.58.2023.04.11.01.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 01:34:23 -0700 (PDT) From: Johannes Thumshirn To: Greg Kroah-Hartman Cc: JoseJavier.Rodriguez@duagon.com, Jorge.SanjuanGarcia@duagon.com, linux-kernel@vger.kernel.org, Jorge Sanjuan Garcia , Javier Rodriguez , Johannes Thumshirn Subject: [PATCH 3/3] mcb-lpc: Reallocate memory region to avoid memory overlapping Date: Tue, 11 Apr 2023 10:33:29 +0200 Message-Id: <20230411083329.4506-4-jth@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411083329.4506-1-jth@kernel.org> References: <20230411083329.4506-1-jth@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=0.5 required=5.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762869568499443766?= X-GMAIL-MSGID: =?utf-8?q?1762869568499443766?= From: Rodríguez Barbarin, José Javier mcb-lpc requests a fixed-size memory region to parse the chameleon table, however, if the chameleon table is smaller that the allocated region, it could overlap with the IP Cores' memory regions. After parsing the chameleon table, drop/reallocate the memory region with the actual chameleon table size. Co-developed-by: Jorge Sanjuan Garcia Signed-off-by: Jorge Sanjuan Garcia Signed-off-by: Javier Rodriguez Signed-off-by: Johannes Thumshirn --- drivers/mcb/mcb-lpc.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/drivers/mcb/mcb-lpc.c b/drivers/mcb/mcb-lpc.c index 53decd89876e..a851e0236464 100644 --- a/drivers/mcb/mcb-lpc.c +++ b/drivers/mcb/mcb-lpc.c @@ -23,7 +23,7 @@ static int mcb_lpc_probe(struct platform_device *pdev) { struct resource *res; struct priv *priv; - int ret = 0; + int ret = 0, table_size; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -58,16 +58,43 @@ static int mcb_lpc_probe(struct platform_device *pdev) ret = chameleon_parse_cells(priv->bus, priv->mem->start, priv->base); if (ret < 0) { - mcb_release_bus(priv->bus); - return ret; + goto out_mcb_bus; } - dev_dbg(&pdev->dev, "Found %d cells\n", ret); + table_size = ret; + + if (table_size < CHAM_HEADER_SIZE) { + /* Release the previous resources */ + devm_iounmap(&pdev->dev, priv->base); + devm_release_mem_region(&pdev->dev, priv->mem->start, resource_size(priv->mem)); + + /* Then, allocate it again with the actual chameleon table size */ + res = devm_request_mem_region(&pdev->dev, priv->mem->start, + table_size, + KBUILD_MODNAME); + if (!res) { + dev_err(&pdev->dev, "Failed to request PCI memory\n"); + ret = -EBUSY; + goto out_mcb_bus; + } + + priv->base = devm_ioremap(&pdev->dev, priv->mem->start, table_size); + if (!priv->base) { + dev_err(&pdev->dev, "Cannot ioremap\n"); + ret = -ENOMEM; + goto out_mcb_bus; + } + + platform_set_drvdata(pdev, priv); + } mcb_bus_add_devices(priv->bus); return 0; +out_mcb_bus: + mcb_release_bus(priv->bus); + return ret; } static int mcb_lpc_remove(struct platform_device *pdev)