Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp977409pxb; Wed, 6 Apr 2022 05:52:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx19jxQGS3QPg++kfhDLNLGiOlaAioaBwtht73qxiptkjEAyHJW12vBnb7g5h8zssnDuwv2 X-Received: by 2002:a63:1d0d:0:b0:382:5f9c:9391 with SMTP id d13-20020a631d0d000000b003825f9c9391mr7136132pgd.617.1649249525192; Wed, 06 Apr 2022 05:52:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649249525; cv=none; d=google.com; s=arc-20160816; b=Vxj5twacwiqATifnh6PhMxsF02RKWshzrVrpg/ZeuaFR8Ldh8pKeFt0k/E37+vvtEP BrWjBBuZ7YHLCLW7l3Qncxp7YTEacq8m273e95J+WL0/CU0PpR4lcnuKx4Ookf6RrLjN NoyF5QZEkw+RBH6rxFwjNAIQnlRKl3tu4oN7n8AoN6s1tMWAzyPql76Xo8wQHygSlekW TsNaHblDC72vpBnumaZtWQI33qsaU29JzPeAXNUihCmeaVOp9mFqCgcyIrR1QJ8yNLJd D6Ki8OjkOrQhmRsRgGkpxlPhNGGdOfHR2Z3qBXuaZvR4Y8KVIBoUi0Ubb40v/SRDFpOZ 6zlw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ovDpuA1/GrWxgao2qDoWzXmWb9Id7GP3OEv+CqR5q1w=; b=QjGNVnIHSDp61Xq9FWsGetJzV+4MhhANbFrldnf84E0Unzsg8L6fsdn2iKxNuFmhBp bNDlw2o9Mt9sQNeAYbF43PU6r7k+jTQFIGMFhturkDYhTVMp+/nuavHzF9+AvluwxaHy mM5DNF+ms9xdS9o2TDunZJfZxyh3g0KjMlQM3+DDsa7sUF+g9w+wLIKEqCm4iKPENpT+ iPnqjatLqrfwlfcJo5bR/eO5aB/3ZgvyvX3Bb/BWIGmzMrMsor5/J7d99WbV02ZoztNx jBEHeDEBqheW8EuXuppyTmXCLGHl4ZrMp8g77O7mPtU0RnevV3iINJp/Pc3nBI0N8dlY RPaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K9X234Pu; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 32-20020a630b20000000b003816043ee1asi15996287pgl.15.2022.04.06.05.52.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:52:05 -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=@linuxfoundation.org header.s=korg header.b=K9X234Pu; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 87CB13C3DCC; Wed, 6 Apr 2022 02:48:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1838948AbiDFA5e (ORCPT + 99 others); Tue, 5 Apr 2022 20:57:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352665AbiDEKEw (ORCPT ); Tue, 5 Apr 2022 06:04:52 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5483ABB910; Tue, 5 Apr 2022 02:53:37 -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 sin.source.kernel.org (Postfix) with ESMTPS id 266BDCE1CA2; Tue, 5 Apr 2022 09:53:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CC72C385A1; Tue, 5 Apr 2022 09:53:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152414; bh=dOC/qeva2LJb0df2IyTGuQKNhvG4/vpycOtEmcS+tso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K9X234PuAWJShF74rKwKyqALJ8eSez9UUIEfHOvNZ/W6yAbmUsIKg3GUqAB3q/RbB YM3puXLyVlInKlbixudn3eAkJGMugNS9Rh8bkoDaqXgtz2bW1NGNoByIGcbju46Xuf oyrZ0Jsnb2IspKDNCbFp8Peb7sDrPIEhJNh7c/cM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.15 768/913] media: atomisp: fix bad usage at error handling logic Date: Tue, 5 Apr 2022 09:30:30 +0200 Message-Id: <20220405070402.853528449@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 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