Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2206514pxp; Mon, 21 Mar 2022 13:52:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy02s57qnMgCk5+Yt1YgGb+ykKf3h+pnMLFtPy49Q+h7fetomeM2wCUEA5WoVX8I0ycLpRv X-Received: by 2002:a62:f205:0:b0:4fa:8461:421f with SMTP id m5-20020a62f205000000b004fa8461421fmr12461157pfh.4.1647895959560; Mon, 21 Mar 2022 13:52:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647895959; cv=none; d=google.com; s=arc-20160816; b=01Ll5VZn7Ab2OlkvYwpK/6QpsHxTUzvSfFZoB4W56yu54ryfWfwzSvomkyBs8QxRm0 g19nIGNIlkirPwe5iqN385arjR8WJnpQaptV62GP35obLtx4+5wtkxnJc67GbgwmDbAs 2RyoHKttoDtoRggNQqEM8sJdW4B7jTaQvBGQcnS++YP/z59boDgIiVIsIRUeQmdPN2n7 ayMRx/OQxX2yS71w+tF7dwvavLO3ZE/QDvipXXSpD0MiVgNxG39xybSCGhFAs5ilpz1h MmTYUEYNIZfXCOJs80MA2HxX4ZsyKAlw3/kPPRFcsRtak6bxaoZljU4h3lKcujQcV2YZ WfbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=+l4q4eQBGuYBAncAJ/7FNjzYbCXQcTb8z0Fti3AjfZE=; b=04sF9zLGzBl5NWE/lpRCTZOIW+k4Qq4Td1+mGp19T2kU5yf0DQJPwSePd4XQDIPsLF q+y5hmUehh7p88ePFfdRqTSJuwhfZY/G0WMfz7kKveCEauvHvseV4JcQct/wobAGWIbC z1pImnRRulCyPPjySG8vyWvAt70/kVk8D6ZPXCg9CkhupW3HwXOz5XqGq0OBj5lNqHTR MgChXpovKk4qgdyrHCof+W3ViIO+T5qDasG/T+01xx8txKQk1KfCXXZe+ljhoxGiz/qJ MqEq2qDlgdf0sW3lpr5/wE/8lfOxQQrVLTZcnLhvfE3xsmMBz5QsSSP7M/sLyikYMxHl MyKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="pKRs/2JE"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id f17-20020a170902ab9100b001542a6e4c9bsi8338891plr.485.2022.03.21.13.52.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 13:52:39 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="pKRs/2JE"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3855E60046; Mon, 21 Mar 2022 13:49:39 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245319AbiCTPJM (ORCPT + 99 others); Sun, 20 Mar 2022 11:09:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245312AbiCTPJL (ORCPT ); Sun, 20 Mar 2022 11:09:11 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79C8D181B05; Sun, 20 Mar 2022 08:07:46 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id kx5-20020a17090b228500b001c6ed9db871so2108944pjb.1; Sun, 20 Mar 2022 08:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id; bh=+l4q4eQBGuYBAncAJ/7FNjzYbCXQcTb8z0Fti3AjfZE=; b=pKRs/2JE10K4Vf6BDYt3+ZiXJI53GJEKLNRdDPyEMO+eAi3qZAiszRRYdUeCvObWnY UX/fxE7cRUoPrh1EBtowQvg36anRqPbzVDrb776T7xCGWNw8Yg6sayI4ugxx3LZ7j1Vd 66Lzfxj3wP9tJh8isZBG7b8z/5uQIwK32EbvrcUmP90tlkIhdR0CkdZ4Q4iAMbCwBGf8 1XPKSY9/JEkwnH0vqs/IeJ6DHNABuTZ5j+QX9kmeKKjXfk9uQqhPJgu4D8yLc4qPvJ8R ARxD4ks/TRyl11SHs0V1KPvK5FGvcaKXFhXdkE4BrnornyFJyN7tL6BoixI0sWBfIt1h oy3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=+l4q4eQBGuYBAncAJ/7FNjzYbCXQcTb8z0Fti3AjfZE=; b=SCloi02Kr43xXFfPSODHTRJlEfWwYA7oE+5inVDL5WHlZ/Ooz3uJqCxlnf6vFv9Zbr aef+bchQGEU6IhlnY7525PmyCz12YmaRIzpDYzv/0qJgFF/ibpZGpa4bqfFbICGb4Irc HdtF0YPe2xGLulNSQ8vR8VS3vpd+xjwNgiSBjiynMqhQhIIwIzE9bxNbdxHZxsheKmER 2336LMGcRNB1Ew2UGeeW+0jsQcakLN7VRg84Wh1btdaRp82AAx4XpIXLzA1WVdGZXETj 0uJvZUVg4D6qrBNdtGUryJoqEOeuodK+qgrdl+Aop2wKix2uyTf36X1/lL7HctmvNmm+ JXqQ== X-Gm-Message-State: AOAM532oTVo9S8DE7WIsbfv1oVpDyZ9uz9H77BZP+7NRIp++szVwwkOu Fj0Sur+Y5+CdUKwnJLPWpDs= X-Received: by 2002:a17:903:244c:b0:154:5ec5:c4a2 with SMTP id l12-20020a170903244c00b001545ec5c4a2mr333552pls.28.1647788865955; Sun, 20 Mar 2022 08:07:45 -0700 (PDT) Received: from localhost.localdomain ([36.24.165.243]) by smtp.googlemail.com with ESMTPSA id u37-20020a056a0009a500b004f820de3dcdsm15901275pfg.9.2022.03.20.08.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Mar 2022 08:07:45 -0700 (PDT) From: Xiaomeng Tong To: alim.akhtar@samsung.com Cc: avri.altman@wdc.com, jejb@linux.ibm.com, martin.petersen@oracle.com, daejun7.park@samsung.com, beanhuo@micron.com, bvanassche@acm.org, keosung.park@samsung.com, gregkh@linuxfoundation.org, stanley.chu@mediatek.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, jakobkoschel@gmail.com, Xiaomeng Tong Subject: [PATCH v2] ufs: fix an NULL check on list iterator Date: Sun, 20 Mar 2022 23:07:33 +0800 Message-Id: <20220320150733.21824-1-xiam0nd.tong@gmail.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The list iterator is always non-NULL so the check 'if (!rgn)' is always false and the dev_err() is never called. Move the check outside the loop and determine if 'victim_rgn' is NULL, to fix this bug. Fixes: 4b5f49079c52a ("scsi: ufs: ufshpb: L2P map management for HPB read") Signed-off-by: Xiaomeng Tong --- changes since v1: - move the check outside the loop (Jakob Koschel) v1: https://lore.kernel.org/all/20220319042657.21835-1-xiam0nd.tong@gmail.com/ --- drivers/scsi/ufs/ufshpb.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 2d36a0715fca..b34feba1f53d 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -869,12 +869,6 @@ static struct ufshpb_region *ufshpb_victim_lru_info(struct ufshpb_lu *hpb) struct ufshpb_region *rgn, *victim_rgn = NULL; list_for_each_entry(rgn, &lru_info->lh_lru_rgn, list_lru_rgn) { - if (!rgn) { - dev_err(&hpb->sdev_ufs_lu->sdev_dev, - "%s: no region allocated\n", - __func__); - return NULL; - } if (ufshpb_check_srgns_issue_state(hpb, rgn)) continue; @@ -890,6 +884,11 @@ static struct ufshpb_region *ufshpb_victim_lru_info(struct ufshpb_lu *hpb) break; } + if (!victim_rgn) + dev_err(&hpb->sdev_ufs_lu->sdev_dev, + "%s: no region allocated\n", + __func__); + return victim_rgn; } base-commit: 14702b3b2438e2f2d07ae93b5d695c166e5c83d1 -- 2.17.1