Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp819587rdg; Fri, 13 Oct 2023 01:57:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHyy8IWlLujHPYAvuvtWVI2DqHsFJOZVysABRYSIIK3M961M0VSFg4VL3pm9ZKxts3N5Jgq X-Received: by 2002:a05:6a20:3cac:b0:15d:9ee7:1816 with SMTP id b44-20020a056a203cac00b0015d9ee71816mr32633003pzj.10.1697187478828; Fri, 13 Oct 2023 01:57:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697187478; cv=none; d=google.com; s=arc-20160816; b=Va3psDmUMAZFHo4yKwe/m+wLfbUV7icnPfisgBaH80uhBbkzrDGzj9sZxhgb82dgFU 6ShP1WqQjfLGTb7qtjXJFoMU9mCaiX/1VX7/0a/fy0aBFeh4PQusFD7Aihc0i0lqURNn NoRPfYHjbNHowovBEbXK9kg9IbBhxpSEOCQxpWKn61/E290qT2w2GRQSXwxGNGNqbtpI AfH8G2ldaWY0+UZ9WNFN2ujlJEvsJwEA/yBv2eQXF6rTjEDL6Ubq7y5VcgG8divc+1XV hHvUYXCvlJ248P3+yTyvlUrF8IagP+eUi51dwAHOPkMw5ot24oNskBcDsv1PQi249r11 65VA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=MG2PDKZgtwn9tI+mReMH4pOSSczrxkXZSYC4fnMYM5c=; fh=oJx2KX6S9LL6lDqlYpYTLQ7S0UoxYChHjrY5DF8+ajk=; b=nJf2JSH9YdgW2wUxFCq1I8jR4Jgc6sIXgER/gYgOcmQzNTntW4Fe/kk45MjUnHuiBQ DStbasXQ8wimsJq7Ca8Szz62hV/HJY6BmUp1k3oT4Q9HNhtGrG1r2ULG22o07CCtC4jC sAll7lOebYCz1EMRR8pDYAlomK0dHdMJVOqtjS+5Smy/AVH4DKXgED2BsIp4onjF+RDW Jj/RIn3escj1XR7Yvh0DYyIsxVYH8JyYNzpT+r0cTJtowEd3Te5AWeto/oSwGIhDYYae rEpk4w2AO0pvF0jck+qyc9T66ChdqbjNFD5efHoTcv58Jed28I5dJ7KuuZ8nhlCHKnsc NJUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="QA/UUN8S"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id w5-20020a170902e88500b001c9e422c587si3087958plg.368.2023.10.13.01.57.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 01:57:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="QA/UUN8S"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 0882081B5AAC; Fri, 13 Oct 2023 01:57:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230255AbjJMI5r (ORCPT + 99 others); Fri, 13 Oct 2023 04:57:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230193AbjJMI5p (ORCPT ); Fri, 13 Oct 2023 04:57:45 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCE25B8; Fri, 13 Oct 2023 01:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697187464; x=1728723464; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=h5m5ctsCvAex9DpLpCjOPM49S/+k402kl9JdKLI4A4U=; b=QA/UUN8S5wYH08BJHW7psYmhtmWTTFNVg3SjGdVRFyct1H2lVh22yl9Y jUvfAsbhdfizBYxZ8pnETztC1vVX9hk1GCvNBau+6PeIsn5FD7EVxvGax j1z+JUuPD8m6OW33CfYFlVGTiBq/vhqeiDoJhqKUMQlVE9OIVvQ8cRPlP /CVJaHP4MFWJBquYfDFcR4XqE9PV58yqrx99n0gx2891VOtIYmDvZcK9G xKWDTBc4x3e6TptaKGefrm9TQPCQFB6ct9+QdMEze+Atckc5M2L3a65E3 WZ6+zABeSq4kY9a5EtJVYB9P8C3gCycywxTerChiq5IbUesP19n+VKIxS g==; X-IronPort-AV: E=McAfee;i="6600,9927,10861"; a="365397256" X-IronPort-AV: E=Sophos;i="6.03,221,1694761200"; d="scan'208";a="365397256" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2023 01:57:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10861"; a="1086060791" X-IronPort-AV: E=Sophos;i="6.03,221,1694761200"; d="scan'208";a="1086060791" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2023 01:57:41 -0700 From: Michal Wilczynski To: nvdimm@lists.linux.dev, linux-acpi@vger.kernel.org, dan.j.williams@intel.com Cc: rafael@kernel.org, vishal.l.verma@intel.com, lenb@kernel.org, dave.jiang@intel.com, ira.weiny@intel.com, linux-kernel@vger.kernel.org, Michal Wilczynski , Andy Shevchenko Subject: [PATCH v2] ACPI: NFIT: Fix local use of devm_*() Date: Fri, 13 Oct 2023 11:57:22 +0300 Message-ID: <20231013085722.3031537-1-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 13 Oct 2023 01:57:55 -0700 (PDT) devm_*() family of functions purpose is managing memory attached to a device. So in general it should only be used for allocations that should last for the whole lifecycle of the device. This is not the case for acpi_nfit_init_interleave_set(). There are two allocations that are only used locally in this function. Fix this by switching from devm_kcalloc() to kcalloc(), and adding modern scope based rollback. This is similar to C++ RAII and is preferred way for handling local memory allocations. Reported-by: Andy Shevchenko Suggested-by: Dave Jiang Suggested-by: Andy Shevchenko Reviewed-by: Dave Jiang Reviewed-by: Andy Shevchenko Signed-off-by: Michal Wilczynski --- v2: - removed first commit from the patchset, as the commit couldn't be marked as a fix - squashed those commits together, since the second one were mostly overwriting the previous one drivers/acpi/nfit/core.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c index 3826f49d481b..67a844a705c4 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -2257,26 +2257,23 @@ static int acpi_nfit_init_interleave_set(struct acpi_nfit_desc *acpi_desc, struct nd_region_desc *ndr_desc, struct acpi_nfit_system_address *spa) { + u16 nr = ndr_desc->num_mappings; + struct nfit_set_info2 *info2 __free(kfree) = + kcalloc(nr, sizeof(*info2), GFP_KERNEL); + struct nfit_set_info *info __free(kfree) = + kcalloc(nr, sizeof(*info), GFP_KERNEL); struct device *dev = acpi_desc->dev; struct nd_interleave_set *nd_set; - u16 nr = ndr_desc->num_mappings; - struct nfit_set_info2 *info2; - struct nfit_set_info *info; int i; + if (!info || !info2) + return -ENOMEM; + nd_set = devm_kzalloc(dev, sizeof(*nd_set), GFP_KERNEL); if (!nd_set) return -ENOMEM; import_guid(&nd_set->type_guid, spa->range_guid); - info = devm_kcalloc(dev, nr, sizeof(*info), GFP_KERNEL); - if (!info) - return -ENOMEM; - - info2 = devm_kcalloc(dev, nr, sizeof(*info2), GFP_KERNEL); - if (!info2) - return -ENOMEM; - for (i = 0; i < nr; i++) { struct nd_mapping_desc *mapping = &ndr_desc->mapping[i]; struct nvdimm *nvdimm = mapping->nvdimm; @@ -2337,8 +2334,6 @@ static int acpi_nfit_init_interleave_set(struct acpi_nfit_desc *acpi_desc, } ndr_desc->nd_set = nd_set; - devm_kfree(dev, info); - devm_kfree(dev, info2); return 0; } -- 2.41.0