Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp734708lqe; Sun, 7 Apr 2024 01:04:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUFiNyTGlwg27bPmcGmvYe3/2G3heUiqOVJCg1eIDiMAjw7ujY7WlPb6EHK7mCwqU3tyXF4iqexc4OX6aw4EGWm8Odfg4C+Gl18jkH2WQ== X-Google-Smtp-Source: AGHT+IEmck4YN2o/F1phIAZqkMg0mSD/Q+dYIeRsnF+7KK99uqjrLy5bzAnoOsMidl2BvlspLiNs X-Received: by 2002:a17:902:a386:b0:1e3:dfdd:21c0 with SMTP id x6-20020a170902a38600b001e3dfdd21c0mr2388489pla.27.1712477079606; Sun, 07 Apr 2024 01:04:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712477079; cv=pass; d=google.com; s=arc-20160816; b=KNgWcdYHmZyef/rPXCscaxCu5uiEZDaVeuI2QZ8pw9XN5tdpNHfOG15R06sZuIqWMh /44cPC5UB6Ypj+i9yeh2FDN0b389Ojl3YDrarvJH7rTcG9Utayz75fBcV3ICZkUmqVKA ppoSYBIY3T1a+RAK0L6LP/xmrCnJm6AobIPv5c1NcFcMDkqwoa2s40zh6IdvM5rUbogn kE7n65tPECdkkUvuctyqtUa5vUf6LWtT2WVkxAY+6mCp2atQPWk6bvvXO/sZks2d6vOp b+NcFF+Szd1tF6pprKucOALEnMj96eexF5DhCI/MEd58lJs/vgl+slNkEFpmyqypgp7q QvZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=xFchYlFNuSl96wvftV2QOKCK/BbFAoyw3htvDX6QCrw=; fh=VzMToBYo5MUfLaQO74C2Chjt/otG4r80qnd7ynZ/RBQ=; b=CSpvn6se7BLug07vwBZVhE4nzn6zVwwDNcZzWPME/LQaL7Ho+eUfu2CvI3qytGvsic qlETIBugB239jVDfCDLfRHAeiilAN18sdckBpsevlg5BjdEeoxCyfDVdelfPs9GLyupm SlU5+6VyXocsr0FqR/jvz7U6po4haM2n9E609nc1E5iKe1cdJYm9wKhsiYDjdWXu2xae +0x6laNZJ9fcUoVLDGLaRtpqDLBBOV3ZCHmVsuEZ3fooz4PVH41ZOYmxWaUUwOaiKni2 Wp5FqSab6XPLVmHkRpqsqoY3tF5fSKuXN7hDf3Ko2bAu8SeEo2Iznn2ItaQlm7x0apP9 6yQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-crypto+bounces-3381-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-3381-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ma16-20020a170903095000b001e2866974f3si769455plb.251.2024.04.07.01.04.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 01:04:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-3381-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-crypto+bounces-3381-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-3381-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id EC135282131 for ; Sun, 7 Apr 2024 08:04:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D28710A16; Sun, 7 Apr 2024 08:04:34 +0000 (UTC) X-Original-To: linux-crypto@vger.kernel.org Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25E2AF9CC; Sun, 7 Apr 2024 08:04:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712477074; cv=none; b=V9qio7cjFhVfWpB3mUYbChevNUIUPn+w6gToKQsfdIkTnwn3/pZNn6k/xzWJLzlvYVJWM6LM06UsCGadfLHGptbSxz03KiZqPuuBrBLDP/Z7Uzxk3qtBZvgvDfPIXRPzTcUBmgyIKo6umWz/ImAl7RlORq8C7uTC/A0iwhhtr58= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712477074; c=relaxed/simple; bh=4X7bb0ikerFe5yNJkCqO9owSgxH9ZYXoE8odVRPTh8M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PiC6lXvXk6jM3B78CJsCmNzJXNzgGcW+qoLdZicnPf9KIuUrcZ1xeWypFA/afhKlbRdCMj2tZRmVHbgsieNHSIrokLz/0K0WYf4mW/W3nw+8p3npo2gOJiazDgm/sbr51GZjTX39dqCb2bfQbJRGXn335PU8ykRzw7b4qr28h1E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VC4S15gkHzwRTk; Sun, 7 Apr 2024 16:01:37 +0800 (CST) Received: from kwepemi500025.china.huawei.com (unknown [7.221.188.170]) by mail.maildlp.com (Postfix) with ESMTPS id D7EEA180073; Sun, 7 Apr 2024 16:04:29 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemi500025.china.huawei.com (7.221.188.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Sun, 7 Apr 2024 16:04:29 +0800 From: Chenghai Huang To: , CC: , , , , , , , , , , , Subject: [PATCH v2 2/9] crypto: hisilicon/debugfs - Fix debugfs uninit process issue Date: Sun, 7 Apr 2024 15:59:53 +0800 Message-ID: <20240407080000.673435-3-huangchenghai2@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240407080000.673435-1-huangchenghai2@huawei.com> References: <20240407080000.673435-1-huangchenghai2@huawei.com> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500025.china.huawei.com (7.221.188.170) During the zip probe process, the debugfs failure does not stop the probe. When debugfs initialization fails, jumping to the error branch will also release regs, in addition to its own rollback operation. As a result, it may be released repeatedly during the regs uninit process. Therefore, the null check needs to be added to the regs uninit process. Signed-off-by: Chenghai Huang --- drivers/crypto/hisilicon/debugfs.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/hisilicon/debugfs.c b/drivers/crypto/hisilicon/debugfs.c index cd67fa348ca7..6351a452878d 100644 --- a/drivers/crypto/hisilicon/debugfs.c +++ b/drivers/crypto/hisilicon/debugfs.c @@ -809,8 +809,14 @@ static void dfx_regs_uninit(struct hisi_qm *qm, { int i; + if (!dregs) + return; + /* Setting the pointer is NULL to prevent double free */ for (i = 0; i < reg_len; i++) { + if (!dregs[i].regs) + continue; + kfree(dregs[i].regs); dregs[i].regs = NULL; } @@ -860,14 +866,21 @@ static struct dfx_diff_registers *dfx_regs_init(struct hisi_qm *qm, static int qm_diff_regs_init(struct hisi_qm *qm, struct dfx_diff_registers *dregs, u32 reg_len) { + int ret; + qm->debug.qm_diff_regs = dfx_regs_init(qm, qm_diff_regs, ARRAY_SIZE(qm_diff_regs)); - if (IS_ERR(qm->debug.qm_diff_regs)) - return PTR_ERR(qm->debug.qm_diff_regs); + if (IS_ERR(qm->debug.qm_diff_regs)) { + ret = PTR_ERR(qm->debug.qm_diff_regs); + qm->debug.qm_diff_regs = NULL; + return ret; + } qm->debug.acc_diff_regs = dfx_regs_init(qm, dregs, reg_len); if (IS_ERR(qm->debug.acc_diff_regs)) { dfx_regs_uninit(qm, qm->debug.qm_diff_regs, ARRAY_SIZE(qm_diff_regs)); - return PTR_ERR(qm->debug.acc_diff_regs); + ret = PTR_ERR(qm->debug.acc_diff_regs); + qm->debug.acc_diff_regs = NULL; + return ret; } return 0; @@ -908,7 +921,9 @@ static int qm_last_regs_init(struct hisi_qm *qm) static void qm_diff_regs_uninit(struct hisi_qm *qm, u32 reg_len) { dfx_regs_uninit(qm, qm->debug.acc_diff_regs, reg_len); + qm->debug.acc_diff_regs = NULL; dfx_regs_uninit(qm, qm->debug.qm_diff_regs, ARRAY_SIZE(qm_diff_regs)); + qm->debug.qm_diff_regs = NULL; } /** -- 2.30.0