Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1761254pxb; Wed, 30 Mar 2022 09:34:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTCTwF0stdEOUqaLehWOYzviTTZZwE36wFByaviSt4L8Y14TDbIVRtQfOTTOq7q2ruEmY8 X-Received: by 2002:aca:6254:0:b0:2da:1b96:f8eb with SMTP id w81-20020aca6254000000b002da1b96f8ebmr276539oib.232.1648658074823; Wed, 30 Mar 2022 09:34:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648658074; cv=none; d=google.com; s=arc-20160816; b=Qp3d7XE7WcsBZP1gqWHg9x2mkxDI6VfqsDeqWm9xDJiYwW+U/hijPPy9RFUJaHfuAi gDfYOKjgYp1lFA04aA9NnywMThYQBeoFuks1ZkNapvpusnEUF8BBx0wubfUcGUQ1Izha NUgvWqsB6Ocdj7mQAfMGqucFNOBVILnbX9frzyVI+yXfSzRA6aHy6GWr/TP4BQqnLsNs fJ78l05Prsw9uMORCEqZqRz9PUqsvlxDe3/2fNdJZfpm295qIgTwkfkx3fAQYsgx4g5e QTLwhFxMfH7p8df9nIKK85/oiFrBuYlfrsjc3aljCXvpQqK7iXolQI6xr12SEbhFdpPu gJlQ== 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=ovDpuA1/GrWxgao2qDoWzXmWb9Id7GP3OEv+CqR5q1w=; b=UKxv/ugr7fdnyoqYhB/L8wqW5YND1FFErv/k8VEqU2yPWvv+ECPL55HhemvLozih5e qujwcLrIEu/eNu4etX0NwPK18DksvkF/6t5ZNGqIZAkRFM70z7CYMzMBCTvxpg8pBlEb 4dbSsSIotrzP8FIu4e6BNOZd3/akXltisiBAYgEmEK2GCXnr4+kDDXyg+IFm3mfc+wbe /nmt7DsxGqKTv45Cq3C+45xNcW1Gssl4vqz/qbufx2KrbPm2SDXkrR9441WBGyXKXuDR mppQaqxQVPybozkyCtReFcrB4f9vJEV8zhnLtDm6zkAdb3U44ldsmkVC/O8B5sy2E0FV /Utg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EnkErwXp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m20-20020a0568080f1400b002ef0c3475b7si23287075oiw.55.2022.03.30.09.34.21; Wed, 30 Mar 2022 09:34:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EnkErwXp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345092AbiC3MDK (ORCPT + 99 others); Wed, 30 Mar 2022 08:03:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345029AbiC3Lxx (ORCPT ); Wed, 30 Mar 2022 07:53:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6911C25F67E; Wed, 30 Mar 2022 04:50:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5DA31B81C3A; Wed, 30 Mar 2022 11:50:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AE8FC340F3; Wed, 30 Mar 2022 11:50:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648641002; bh=dOC/qeva2LJb0df2IyTGuQKNhvG4/vpycOtEmcS+tso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EnkErwXpH40IHyW4DHo+2aiqfWtazMriJvF18/HufMxctjgskMJi5WPIuCXJvBs/Q VE/OSp7KzKAs6MnDPO//Dr7o+VNNk+8EsbG2pYe7SWTk1pMaMAM+UbC6sciY3I1dRS ZB0r6o6tV9/zzvjJJX4H4fJQCs9bPE2GoSNHfUpG4PDW6Ol+BHyP4ildxdDgMKD0hQ xhSVuGHxe/SJ7Fe7C9mUDiZW295fDnHC4495sPS0zRBBkLlCp6ReibDMjjN6EoE0Nq hvEU7AIaIiWRVUgpxmIHpzgkI73jun6aJ7pEW1C5RTSqbxBWQDGwyYKqshBJ378JYz Ix/wEOHC2O09g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mauro Carvalho Chehab , Hans Verkuil , Sasha Levin , gregkh@linuxfoundation.org, linux-media@vger.kernel.org, devel@driverdev.osuosl.org Subject: [PATCH AUTOSEL 5.16 58/59] media: atomisp: fix bad usage at error handling logic Date: Wed, 30 Mar 2022 07:48:30 -0400 Message-Id: <20220330114831.1670235-58-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220330114831.1670235-1-sashal@kernel.org> References: <20220330114831.1670235-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Mauro Carvalho Chehab [ Upstream commit fc0b582c858ed73f94c8f3375c203ea46f1f7402 ] As warned by sparse: atomisp: drivers/staging/media/atomisp/pci/atomisp_acc.c:508 atomisp_acc_load_extensions() warn: iterator used outside loop: 'acc_fw' The acc_fw interactor is used outside the loop, at the error handling logic. On most cases, this is actually safe there, but, if atomisp_css_set_acc_parameters() has an error, an attempt to use it will pick an invalid value for acc_fw. Reported-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- .../staging/media/atomisp/pci/atomisp_acc.c | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_acc.c b/drivers/staging/media/atomisp/pci/atomisp_acc.c index 9a1751895ab0..28cb271663c4 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_acc.c +++ b/drivers/staging/media/atomisp/pci/atomisp_acc.c @@ -439,6 +439,18 @@ int atomisp_acc_s_mapped_arg(struct atomisp_sub_device *asd, return 0; } +static void atomisp_acc_unload_some_extensions(struct atomisp_sub_device *asd, + int i, + struct atomisp_acc_fw *acc_fw) +{ + while (--i >= 0) { + if (acc_fw->flags & acc_flag_to_pipe[i].flag) { + atomisp_css_unload_acc_extension(asd, acc_fw->fw, + acc_flag_to_pipe[i].pipe_id); + } + } +} + /* * Appends the loaded acceleration binary extensions to the * current ISP mode. Must be called just before sh_css_start(). @@ -479,16 +491,20 @@ int atomisp_acc_load_extensions(struct atomisp_sub_device *asd) acc_fw->fw, acc_flag_to_pipe[i].pipe_id, acc_fw->type); - if (ret) + if (ret) { + atomisp_acc_unload_some_extensions(asd, i, acc_fw); goto error; + } ext_loaded = true; } } ret = atomisp_css_set_acc_parameters(acc_fw); - if (ret < 0) + if (ret < 0) { + atomisp_acc_unload_some_extensions(asd, i, acc_fw); goto error; + } } if (!ext_loaded) @@ -497,6 +513,7 @@ int atomisp_acc_load_extensions(struct atomisp_sub_device *asd) ret = atomisp_css_update_stream(asd); if (ret) { dev_err(isp->dev, "%s: update stream failed.\n", __func__); + atomisp_acc_unload_extensions(asd); goto error; } @@ -504,13 +521,6 @@ int atomisp_acc_load_extensions(struct atomisp_sub_device *asd) return 0; error: - while (--i >= 0) { - if (acc_fw->flags & acc_flag_to_pipe[i].flag) { - atomisp_css_unload_acc_extension(asd, acc_fw->fw, - acc_flag_to_pipe[i].pipe_id); - } - } - list_for_each_entry_continue_reverse(acc_fw, &asd->acc.fw, list) { if (acc_fw->type != ATOMISP_ACC_FW_LOAD_TYPE_OUTPUT && acc_fw->type != ATOMISP_ACC_FW_LOAD_TYPE_VIEWFINDER) -- 2.34.1