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)