Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp650648pxb; Tue, 5 Apr 2022 17:19:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzoT+tMCZT80AzflcU2SvxnTS541K1NOCP+/FY1UhasJWRyR9SbBlfFtpfiNCXkjs0Skm0 X-Received: by 2002:a05:6402:2805:b0:41b:630b:de68 with SMTP id h5-20020a056402280500b0041b630bde68mr6127695ede.143.1649204290635; Tue, 05 Apr 2022 17:18:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649204290; cv=none; d=google.com; s=arc-20160816; b=hba8Vi/9o9HL7DQAkZfrl0HkrnvkDJmC5solsx5HG5nPpP8mNpEqWIcS9cZx7DkFSd ohJtobdATlZkXJszbRA+i3QO/FPlqlMLqzisQUjtsxMyqnGCVJSy3g5iMI+aLWQXlCVB w0solR5JIZ+BTaMakw0QKstorEXXAHoxZMn6Uyco5PJFAbOLDN3vriLo2B8XVxoOqNjh xr8jiKXoBJU1u2gMTZ8RvnbqDltpzgaOW6iSFMKje5g3ZZn/WSiPnqd/buLVq/W9RXu4 OJ3Jq6McHvJy96Z9K6Ax1AKboLtuyACbV1qH1XXf3vctarCb0mKz4anIg1RhrVMPHgJD KcbQ== 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=cNZ3LzqvfpcEyc/OlXZHN0NiWe0plfm0HFzZUqtZbZ8xo/qxZOuo5SmStEPdpQaK6V n2aEZBX96NfN1AHEYu5qkwZ9YRpXdev9Hxs3zGldku7MdGqoPzGtgpQW0ZolneJJjbWI fTBYL9dqLwh2khiJnUZZtKCfyljSx+EyVLnvMMz1pRWKj41s8gG7O569FGfsfrrvyY9H 70CAkNzBts5u9s24ILBooe0h+OBH4vrQKvvf8jiiTpr/5j/84p2IX6QJuf/DnDDKMYcT HEmT6wK5ftF0+rVr3x1NC5pF2/8ZtAZPLafLzpje0l6GETypJkKnUG5Tjr18axhQ4WNc O/sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rRMEqPuw; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a3-20020a50e703000000b0041cd9ea80acsi4861891edn.507.2022.04.05.17.17.45; Tue, 05 Apr 2022 17:18:10 -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=@linuxfoundation.org header.s=korg header.b=rRMEqPuw; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390620AbiDENmk (ORCPT + 99 others); Tue, 5 Apr 2022 09:42:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345317AbiDEJWZ (ORCPT ); Tue, 5 Apr 2022 05:22:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59E8E4338C; Tue, 5 Apr 2022 02:10:29 -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 E7489B81A12; Tue, 5 Apr 2022 09:10:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E4F2C385A2; Tue, 5 Apr 2022 09:10:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149826; bh=dOC/qeva2LJb0df2IyTGuQKNhvG4/vpycOtEmcS+tso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rRMEqPuwWQ3tg9Zr9GxnR8U5d4nxvdssKVR/uYF4k7m07hIC7EBFY5SD/kw9Fdld6 aHjjveeA9N0vXhqQgZeJrm0boebnDPnrH26+vMhErU2ADSgva27TEjymyilk2COmo4 MRgu3hNaZb29sDjw1LKzfvRcHojI+EJzSHK4uIwQ= 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.16 0855/1017] media: atomisp: fix bad usage at error handling logic Date: Tue, 5 Apr 2022 09:29:28 +0200 Message-Id: <20220405070419.615422796@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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=-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