From patchwork Mon Oct 17 15:32:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 13008993 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98CE6C433FE for ; Mon, 17 Oct 2022 15:32:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230228AbiJQPch (ORCPT ); Mon, 17 Oct 2022 11:32:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229799AbiJQPcg (ORCPT ); Mon, 17 Oct 2022 11:32:36 -0400 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82C3F12753 for ; Mon, 17 Oct 2022 08:32:34 -0700 (PDT) Received: by mail-qv1-xf32.google.com with SMTP id o67so7596600qvo.13 for ; Mon, 17 Oct 2022 08:32:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DlhvucNsh6lQT97rBrPoKSr6IXxVRQV41qr8MDssIYE=; b=EDom+IoiFDuJbrTIuwrT+vuKLbE7XaHjABuPUcfwKE6RW86oI8UyKYP2vdgjS3YvYU fiSl22UKVMTbJiHFKGeW/yxojAXiBAPSeb1xAw/WbLZxy1aYEloRv//uWs76IQ/I5Xlt LAP9gBO+0JpqIyOXe1dDneDmx1FbTRaB2G+YQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DlhvucNsh6lQT97rBrPoKSr6IXxVRQV41qr8MDssIYE=; b=MbQ14kv2JTkuQf7+PlgIkSZlOkaCvt5DpAJnAgbAU3SmLoSTgOOdTZBPPnqe9qhrz5 Xf4lKa3qf8eA4YRstpGDy/0cV66dDa249QrzllcB7sOnR64GsW6yaB74yIKg3PMZVXzH w5wnPgzwpvUgzFcZnPLvQWwUFBhYE011L5l+VW9lxtRYjkwooShZz4qcKaG5W+GvRlWM 5LoJITKig01h+JfTpvp6seABk27ZukiqsbxEGkeNGV0qhX+GeEvi3RCW3YwByyyGPLBd 7T9Pfab7E9QMKJyQsPD99DTsCjUEiwNz/VxgMsUAaUw865u23uhWqcW8dxryQ2ObTJUa CbtQ== X-Gm-Message-State: ACrzQf327DuaTlWLPHKJszlsVhaJXkOHTMRoTRywmX71gPwBcQs0UWyR ZnKUr3hcgbXBkT1WBwhwO3bmPaFe7N6cHCOI X-Google-Smtp-Source: AMsMyM7BtuZDHRWLZJ21rHzzkku4D7OVQqV7OfZhuEXtl9JDOCB3I+yB2KflX6bQs+YS3xjetVYnVw== X-Received: by 2002:a05:6214:2306:b0:473:f77a:85a7 with SMTP id gc6-20020a056214230600b00473f77a85a7mr8711588qvb.106.1666020753313; Mon, 17 Oct 2022 08:32:33 -0700 (PDT) Received: from localhost.swdvt.lab.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id m10-20020ac8444a000000b0039b03ac2f72sm42321qtn.46.2022.10.17.08.32.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Oct 2022 08:32:30 -0700 (PDT) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, kuba@kernel.org, edumazet@google.com, pabeni@redhat.com, gospo@broadcom.com, vikas.gupta@broadcom.com Subject: [PATCH net] bnxt_en: fix memory leak in bnxt_nvm_test() Date: Mon, 17 Oct 2022 11:32:22 -0400 Message-Id: <1666020742-25834-1-git-send-email-michael.chan@broadcom.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vikas Gupta Free the kzalloc'ed buffer before returning in the success path. Fixes: 5b6ff128fdf6 ("bnxt_en: implement callbacks for devlink selftests") Signed-off-by: Vikas Gupta Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c index a36803e79e92..8a6f788f6294 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c @@ -613,6 +613,7 @@ static int bnxt_dl_reload_up(struct devlink *dl, enum devlink_reload_action acti static bool bnxt_nvm_test(struct bnxt *bp, struct netlink_ext_ack *extack) { + bool rc = false; u32 datalen; u16 index; u8 *buf; @@ -632,20 +633,20 @@ static bool bnxt_nvm_test(struct bnxt *bp, struct netlink_ext_ack *extack) if (bnxt_get_nvram_item(bp->dev, index, 0, datalen, buf)) { NL_SET_ERR_MSG_MOD(extack, "nvm test vpd read error"); - goto err; + goto done; } if (bnxt_flash_nvram(bp->dev, BNX_DIR_TYPE_VPD, BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, 0, 0, buf, datalen)) { NL_SET_ERR_MSG_MOD(extack, "nvm test vpd write error"); - goto err; + goto done; } - return true; + rc = true; -err: +done: kfree(buf); - return false; + return rc; } static bool bnxt_dl_selftest_check(struct devlink *dl, unsigned int id,