Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp273768rdf; Thu, 2 Nov 2023 23:17:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFT+O02wd59sYSIdQ/j4hrUVOvC3r63UYOyHIiPDCY2V8ajGtZcLQofiVRal6Qje8O69MmW X-Received: by 2002:a17:903:442:b0:1ca:8541:e1fe with SMTP id iw2-20020a170903044200b001ca8541e1femr17291507plb.62.1698992237558; Thu, 02 Nov 2023 23:17:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698992237; cv=none; d=google.com; s=arc-20160816; b=fI0kN+5CFyYr4r2AmSxFT0E4Z8j2nb9XCz+IujdsuPtytZgf1g1X+p4C0HJcZpZ19T FGrn6Umg/uYuRKDPWc/Ho8lthBmF57fN5IaHfTBapD247gNQ4zLbpzFMKjslfNk78Scx MePOEft/ZCpmp9cXosrKtNRqxLe/vIKivJ8OehiyHiGKYnxSI+jOj9X9XKCR+/vyocDU iKegs5uVDIlFVi+gTXgs8c5XJyJ/z71VDyF1R7hWm/Pqh8VhUKsMlnn7EOGGR33FvaIr GOzuuofI90spZDLeMEU6MQlWtuxloR7H9AWJaNo3dvGdt65F8uT6+tM5z6gS1HqFQgr7 8cGQ== 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 :dkim-signature; bh=2O/2ScZ3CygF88mlMVLZxyoGI2VWLFlNiAqo0wuDir4=; fh=J5fZGSGUmoD0NT+ZfFkgng7qPhvONoMGdVOrNctU85A=; b=05LGreoV/Kz1gflwi01mVy5OVDDvmrtXYGPHz7iexg1LzljdawR1QGC1tTQ95ZGy2f jAZcfOEcXp1GQfSwwpf6LAN8tPsqe0gCG9cw/y/6N32n2X3n82YHYeioyR5flDUyHt+D 1lYG5UJYzsCEicYAg1y0I8D+j23vg+AEbYHPn5KXSkytQWu+ViKRfj5JGIwrftHFahFf rG88aKkXVYUImLGO5Rk5peTd2+lXhNQ4LppFD9r7BLPoUsrjNj9e2tWw9dwSpGX+S+4L jJ0BsyUMioZ5y+a+UWDolf0X3m2PNIDBgyYYk7pH6H8IPoF0Fevw+AUSz9aQ5atIhlMp Y6Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeconstruct.com.au header.s=2022a header.b=AcFz9XeO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeconstruct.com.au Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id b15-20020a170902d50f00b001ca86fa1e1csi961801plg.484.2023.11.02.23.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 23:17:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@codeconstruct.com.au header.s=2022a header.b=AcFz9XeO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeconstruct.com.au Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 1CBEA82698D7; Thu, 2 Nov 2023 23:17:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231674AbjKCGQG (ORCPT + 99 others); Fri, 3 Nov 2023 02:16:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230479AbjKCGPw (ORCPT ); Fri, 3 Nov 2023 02:15:52 -0400 Received: from codeconstruct.com.au (pi.codeconstruct.com.au [203.29.241.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 235571B6 for ; Thu, 2 Nov 2023 23:15:46 -0700 (PDT) Received: from localhost.localdomain (ppp14-2-79-67.adl-apt-pir-bras31.tpg.internode.on.net [14.2.79.67]) by mail.codeconstruct.com.au (Postfix) with ESMTPSA id C388F20237; Fri, 3 Nov 2023 14:15:41 +0800 (AWST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codeconstruct.com.au; s=2022a; t=1698992142; bh=2O/2ScZ3CygF88mlMVLZxyoGI2VWLFlNiAqo0wuDir4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AcFz9XeOEs1SJu6NZFof4sNJOFcXmYH7pSl9+PpGrtirABF4TXEE8e2cEI6KuyaUX l7n+TRiBmY0MmbMwg4ckH+EyzEavC8pTjH5XouUHEZtp4oXWzz/hrPpv+kNoJtNLvC sF2+WQYeymOHy+v3Z4ZXeADLh1Pp7gjx3N0EaKlXCFRtHQ/Ds6dmZtNoNCqSEXb6dD OmIY4hYYqe1MjHD99SHAaA24wMmfYwmDLyQWzsljnutWaomeYGZOWmWxK2xdkyf3wL 5hF2MI/2qYFDqYLJsfRmX7SXRob/NPPy2tt/VgRU5/CF6xpZoKnqg1usCfDk52o89g xF1JAfsXlGn1g== From: Andrew Jeffery To: minyard@acm.org, openipmi-developer@lists.sourceforge.net Cc: Andrew Jeffery , linux-kernel@vger.kernel.org, Jonathan.Cameron@Huawei.com, aladyshev22@gmail.com, jk@codeconstruct.com.au Subject: [PATCH 06/10] ipmi: kcs_bmc: Integrate buffers into driver struct Date: Fri, 3 Nov 2023 16:45:18 +1030 Message-Id: <20231103061522.1268637-7-andrew@codeconstruct.com.au> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231103061522.1268637-1-andrew@codeconstruct.com.au> References: <20231103061522.1268637-1-andrew@codeconstruct.com.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 02 Nov 2023 23:17:05 -0700 (PDT) Consolidate several necessary allocations into one to reduce the number of possible error paths. Signed-off-by: Andrew Jeffery --- drivers/char/ipmi/kcs_bmc_cdev_ipmi.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/drivers/char/ipmi/kcs_bmc_cdev_ipmi.c b/drivers/char/ipmi/kcs_bmc_cdev_ipmi.c index 712a80c27060..45ac930172ec 100644 --- a/drivers/char/ipmi/kcs_bmc_cdev_ipmi.c +++ b/drivers/char/ipmi/kcs_bmc_cdev_ipmi.c @@ -66,6 +66,10 @@ enum kcs_ipmi_errors { KCS_UNSPECIFIED_ERROR = 0xFF }; +#define DEVICE_NAME "ipmi-kcs" +#define KCS_MSG_BUFSIZ 1000 +#define KCS_ZERO_DATA 0 + struct kcs_bmc_ipmi { struct list_head entry; @@ -79,24 +83,18 @@ struct kcs_bmc_ipmi { wait_queue_head_t queue; bool data_in_avail; int data_in_idx; - u8 *data_in; + u8 data_in[KCS_MSG_BUFSIZ]; int data_out_idx; int data_out_len; - u8 *data_out; + u8 data_out[KCS_MSG_BUFSIZ]; struct mutex mutex; - u8 *kbuffer; + u8 kbuffer[KCS_MSG_BUFSIZ]; struct miscdevice miscdev; }; -#define DEVICE_NAME "ipmi-kcs" - -#define KCS_MSG_BUFSIZ 1000 - -#define KCS_ZERO_DATA 0 - /* IPMI 2.0 - Table 9-1, KCS Interface Status Register Bits */ #define KCS_STATUS_STATE(state) (state << 6) #define KCS_STATUS_STATE_MASK GENMASK(7, 6) @@ -478,19 +476,15 @@ static int kcs_bmc_ipmi_add_device(struct kcs_bmc_device *kcs_bmc) spin_lock_init(&priv->lock); mutex_init(&priv->mutex); - init_waitqueue_head(&priv->queue); priv->client.dev = kcs_bmc; priv->client.ops = &kcs_bmc_ipmi_client_ops; - priv->data_in = devm_kmalloc(kcs_bmc->dev, KCS_MSG_BUFSIZ, GFP_KERNEL); - priv->data_out = devm_kmalloc(kcs_bmc->dev, KCS_MSG_BUFSIZ, GFP_KERNEL); - priv->kbuffer = devm_kmalloc(kcs_bmc->dev, KCS_MSG_BUFSIZ, GFP_KERNEL); priv->miscdev.minor = MISC_DYNAMIC_MINOR; priv->miscdev.name = devm_kasprintf(kcs_bmc->dev, GFP_KERNEL, "%s%u", DEVICE_NAME, kcs_bmc->channel); - if (!priv->data_in || !priv->data_out || !priv->kbuffer || !priv->miscdev.name) + if (!priv->miscdev.name) return -EINVAL; priv->miscdev.fops = &kcs_bmc_ipmi_fops; @@ -529,9 +523,6 @@ static void kcs_bmc_ipmi_remove_device(struct kcs_bmc_device *kcs_bmc) misc_deregister(&priv->miscdev); kcs_bmc_disable_device(&priv->client); - devm_kfree(kcs_bmc->dev, priv->kbuffer); - devm_kfree(kcs_bmc->dev, priv->data_out); - devm_kfree(kcs_bmc->dev, priv->data_in); devm_kfree(kcs_bmc->dev, priv); } -- 2.39.2