From patchwork Mon Jun 5 11:37:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1790419 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=joLKFCs9; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=FomuHX4A; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QZYHG0zVVz20Ty for ; Mon, 5 Jun 2023 22:45:30 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EZ8aYluzHfq/Y7I7mOvPK0Wav7DJKgJdLW48QXMRqsM=; b=joLKFCs98+0t/R ZHDvTh8eTXsLfbSCGktrDN5HTMQrWU9VJTK0YnVebtl8DSA66t7x4cw02sRm2AX2iZ33HkpMTt/pt KyYe1Jc0pxnt3xPFYcf8dmDXULdrbhNrAPjX0hXRisRTSpdb5icOQMbzV4QLN0kldgM+ld3jOullE JQdVusFZZrkzL+33kSpu1aGqWuFX6HhHM9sh9p1RzJQyM8DkU/j+8hqvjGwEfct+LvHZEPcGe5Psc oVUVbZ47bG22Y55xiFuR+1Iw6pmm6B7GQwYo7fnDS8l/0EKqXr9qSWKpa2sEwgVs4lR0Zck/2wjHd JVxQd4+EeRfL4y0xgDbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q69aI-00FUjX-36; Mon, 05 Jun 2023 12:45:18 +0000 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q68Xd-00FJ3k-29 for opensbi@lists.infradead.org; Mon, 05 Jun 2023 11:38:31 +0000 Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-39a55e706deso1711995b6e.3 for ; Mon, 05 Jun 2023 04:38:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685965109; x=1688557109; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bWrB0Ls+dDWZ1pCKLNMpo5O7r9aPAk2cuVP7r8O2NbY=; b=FomuHX4Aj/29DgInW1idv5slFx5ftI8B+LvzOVjnFHH26J5iEnoD6xnPaOtNwWl/q6 4Szb2Cai6zgX5XGiShzBwjxBPKtormpnaOXDCZUpS48Lmw5GV337/kzc3BlZKoRojAn+ ZM6dSi+Nkp3AWcy5Yz41cGpP/lkQ49bLNQXTd9Bmwi/8DkYgZcKbdWnY027MK6swA+u/ RzRRRPWn7B03buX+dqT+4RCcADq55tPd+Rl3IM2ZV2rFaHBgkeH7oVWeeTncqO04lRUp 1ktC1PiG/v+xVnBxa96LxBdlnWa4hUWj15bGQNmOxNSZua9SGEkTDcx3VksTIBHZUNl1 9TSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685965109; x=1688557109; 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=bWrB0Ls+dDWZ1pCKLNMpo5O7r9aPAk2cuVP7r8O2NbY=; b=isSv8PZdfzueKok9zJJ6bQVFg0bZ84g+MJW1y3/gAZDvFYsOZ3HHm3deXIWSeUnmxn k+/kIKsKfYZTKSwMjauTvFHGRZGWLniWpK6d7Tgz+E87tkZc7tCFPXi6EWPQTs+NDloR LT/NzVyabkVj/wMb/i6C79X1X1+u7spNJXjfSGKsVLTVrNPz6gaIXOJHITdqu30mijCx wDTItACopq5gAPLH9PmXPpJsNGoh+UHyM52NroGsjxamoFxba/Ae05sbEdO/LxwHX8Iw kSiZWASxGu+50ezscU2TRvFOLbSpTTL916458xqYdJLHpgS1d0XE/uh4pzxxS2vJVNIK 9Grg== X-Gm-Message-State: AC+VfDxuA71Cqsv59ZtP1/hSlgGHkZyy3XCaO/AYwow47xg27KcHmPvX 2L/OEid+e22d3wPq7X3BUtRcNw== X-Google-Smtp-Source: ACHHUZ4vYO+/iJ6r1XiXV1uiRBxMtPb2WM124fFcGpBbaaBTfNc/Vsd+oDh5IZ+d6l4q0hLSzZVzzA== X-Received: by 2002:a05:6808:4d5:b0:398:fde:2116 with SMTP id a21-20020a05680804d500b003980fde2116mr2860078oie.48.1685965108709; Mon, 05 Jun 2023 04:38:28 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id p10-20020a54460a000000b00396324838e7sm3155301oip.10.2023.06.05.04.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 04:38:28 -0700 (PDT) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel , Andrew Jones Subject: [PATCH v2 09/18] lib: utils/i2c: Use heap in DesignWare and SiFive I2C drivers Date: Mon, 5 Jun 2023 17:07:40 +0530 Message-Id: <20230605113749.230696-10-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230605113749.230696-1-apatel@ventanamicro.com> References: <20230605113749.230696-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230605_043829_703437_D42B68FD X-CRM114-Status: GOOD ( 12.27 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Let's use heap allocation in DesignWare and SiFive I2C drivers instead of using a fixed size global array. Signed-off-by: Anup Patel Reviewed-by: Andrew Jones --- lib/utils/i2c/fdt_i2c_dw.c | 24 ++++++++++ lib/utils/i2c/fdt_i2c_sifive.c | 23 [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:233 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Let's use heap allocation in DesignWare and SiFive I2C drivers instead of using a fixed size global array. Signed-off-by: Anup Patel Reviewed-by: Andrew Jones --- lib/utils/i2c/fdt_i2c_dw.c | 24 ++++++++++-------------- lib/utils/i2c/fdt_i2c_sifive.c | 23 ++++++++++------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/lib/utils/i2c/fdt_i2c_dw.c b/lib/utils/i2c/fdt_i2c_dw.c index 71062f4..99b2ddb 100644 --- a/lib/utils/i2c/fdt_i2c_dw.c +++ b/lib/utils/i2c/fdt_i2c_dw.c @@ -9,17 +9,12 @@ #include #include +#include #include #include #include #include -#define FDT_DW_I2C_ADAPTER_MAX 7 - -static unsigned int fdt_dw_i2c_adapter_count; -static struct dw_i2c_adapter - fdt_dw_i2c_adapter_array[FDT_DW_I2C_ADAPTER_MAX]; - extern struct fdt_i2c_adapter fdt_i2c_adapter_dw; static int fdt_dw_i2c_init(void *fdt, int nodeoff, @@ -29,23 +24,24 @@ static int fdt_dw_i2c_init(void *fdt, int nodeoff, struct dw_i2c_adapter *adapter; u64 addr; - if (fdt_dw_i2c_adapter_count >= FDT_DW_I2C_ADAPTER_MAX) - return SBI_ENOSPC; - - adapter = &fdt_dw_i2c_adapter_array[fdt_dw_i2c_adapter_count]; + adapter = sbi_zalloc(sizeof(*adapter)); + if (!adapter) + return SBI_ENOMEM; rc = fdt_get_node_addr_size(fdt, nodeoff, 0, &addr, NULL); - if (rc) + if (rc) { + sbi_free(adapter); return rc; + } adapter->addr = addr; adapter->adapter.driver = &fdt_i2c_adapter_dw; rc = dw_i2c_init(&adapter->adapter, nodeoff); - if (rc) + if (rc) { + sbi_free(adapter); return rc; - - fdt_dw_i2c_adapter_count++; + } return 0; } diff --git a/lib/utils/i2c/fdt_i2c_sifive.c b/lib/utils/i2c/fdt_i2c_sifive.c index 195541c..b85b245 100644 --- a/lib/utils/i2c/fdt_i2c_sifive.c +++ b/lib/utils/i2c/fdt_i2c_sifive.c @@ -9,12 +9,11 @@ #include #include +#include #include #include #include -#define SIFIVE_I2C_ADAPTER_MAX 2 - #define SIFIVE_I2C_PRELO 0x00 #define SIFIVE_I2C_PREHI 0x04 #define SIFIVE_I2C_CTR 0x08 @@ -47,10 +46,6 @@ struct sifive_i2c_adapter { struct i2c_adapter adapter; }; -static unsigned int sifive_i2c_adapter_count; -static struct sifive_i2c_adapter - sifive_i2c_adapter_array[SIFIVE_I2C_ADAPTER_MAX]; - extern struct fdt_i2c_adapter fdt_i2c_adapter_sifive; static inline void sifive_i2c_setreg(struct sifive_i2c_adapter *adap, @@ -244,14 +239,15 @@ static int sifive_i2c_init(void *fdt, int nodeoff, struct sifive_i2c_adapter *adapter; uint64_t addr; - if (sifive_i2c_adapter_count >= SIFIVE_I2C_ADAPTER_MAX) - return SBI_ENOSPC; - - adapter = &sifive_i2c_adapter_array[sifive_i2c_adapter_count]; + adapter = sbi_zalloc(sizeof(*adapter)); + if (!adapter) + return SBI_ENOMEM; rc = fdt_get_node_addr_size(fdt, nodeoff, 0, &addr, NULL); - if (rc) + if (rc) { + sbi_free(adapter); return rc; + } adapter->addr = addr; adapter->adapter.driver = &fdt_i2c_adapter_sifive; @@ -259,10 +255,11 @@ static int sifive_i2c_init(void *fdt, int nodeoff, adapter->adapter.write = sifive_i2c_adapter_write; adapter->adapter.read = sifive_i2c_adapter_read; rc = i2c_adapter_add(&adapter->adapter); - if (rc) + if (rc) { + sbi_free(adapter); return rc; + } - sifive_i2c_adapter_count++; return 0; }