Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp8110592rwn; Wed, 14 Sep 2022 09:05:39 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ylcaTrd0e+/vamawI/QmJ7N2U+1PS8JCrygB0NSSwq3+KUHHfcB1Z2ZvPlBVh/tw8J3Vx X-Received: by 2002:a17:907:1608:b0:77d:7906:6578 with SMTP id hb8-20020a170907160800b0077d79066578mr10635812ejc.533.1663171539294; Wed, 14 Sep 2022 09:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663171539; cv=none; d=google.com; s=arc-20160816; b=wWqYf1gS8+oJUZPpAfzbv41IGmwlxatxbd5DPLE/EImp0N3bseGlIvYUiDBsMeRSN0 oip75aMKWzhRKSeV0kFQXyjek1/jTOSRURbRyFtZ870XtZBGO6LiYIRuonybxDQa7aN7 DZpywMvNn6E5lTlC1R29uYaKm5dGMVGUyQuCPcibntz9XbO24b6BduPYU65e7rZ6/gYQ UPU1XScl32rdtbvscMgJCYoi54JuP+dtxoydxsn6fErsXXMgsllMIcWuZIbeukTyingl Yt1H2U4lOabLiUlvjZG3vURUTz0U4zH6iUkeNNpN8xUYKpVaY2ImACW+2Esa/nHIUWzz Z3WA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=F9uuISKF2XZEmCGT0zVw9l/8wO+PYTvUjx837Ei77to=; b=HM/jBIAUuWeiZMwER8D0Yl4UmLGDAgCI9tMrG4BWNao7KWJ494oqowOs9JnXjG+4U5 0UvBhMD7hPmBg2jDprPH85j2C8iQ8J16VPDNghF2t7Ka7lJ7I7k9CiRTPqSQcViXsOgW vsawhmkDa9xdj+dxrbPh5/L47c+ySkHTCpBpSTNs32g9LpFuxSjWEfWM7a7EH3mgxjz5 Z5cJbHTksvnmJlYo6dGwmoXcalFaAqA0UueSq3DZ8YDB5StnS6yMuWW8gwUC7OJgiYWa 2RetnJ67JIWr0dZPZKEUiTTZq3ziZTvvP2q5tJGnOaTswz7l4lNNSHEEZVuCFMxwcJay 7HCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=RKoQTFo8; 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=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r9-20020a170906548900b0073dced7204bsi9727887ejo.767.2022.09.14.09.05.07; Wed, 14 Sep 2022 09:05:39 -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=@collabora.com header.s=mail header.b=RKoQTFo8; 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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230077AbiINPDW (ORCPT + 99 others); Wed, 14 Sep 2022 11:03:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229906AbiINPDP (ORCPT ); Wed, 14 Sep 2022 11:03:15 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D22274361; Wed, 14 Sep 2022 08:03:14 -0700 (PDT) Received: from dimapc.. (109-252-122-187.nat.spd-mgts.ru [109.252.122.187]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 087C56601BDF; Wed, 14 Sep 2022 16:03:11 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1663167792; bh=MKe6/s3tvLmdyJXZjKooDqWZzASfXtNe2FVvnbAhZLM=; h=From:To:Cc:Subject:Date:From; b=RKoQTFo8BXGuXtV1ZJtrlPH1iX7chZWETLyGqWYcAfSu+PT2P3sRjrQrbdeOok/tg di91k1Bjtixc6gaBuvHWc72tPj4IVVdM3D/blyyTynKXBIZ57KjRJJINHL3JFQigOo 0ykVUxISaO6Ty3jVxSez7Ct6HYQSroGAGsLsvZdi8vgg7nxfqwadw764uzmfvWPEAj JiVPqJ0BCWhQgyXgYByRaYocmJrubd33yH0rKD/jqRKQ598XLaRhUTkMPHpUV+xnwc q0FODgTcS4USQB/2UrGMCd00pMKW8OyGShTcQR6DPYwWs55tl7HcDNhvoZylJNQoXP 43ONzAShPnKlw== From: Dmitry Osipenko To: Maxime Ripard , Paul Kocialkowski , Mauro Carvalho Chehab , Jernej Skrabec , Chen-Yu Tsai , Samuel Holland , Nicolas Dufresne Cc: linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, kernel@collabora.com Subject: [PATCH v1] media: cedrus: Propagate error code from cedrus_h265_skip_bits() Date: Wed, 14 Sep 2022 18:01:05 +0300 Message-Id: <20220914150105.209484-1-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 The cedrus_h265_skip_bits() may get into infinite loop if decoding parameters are incorrect. In this case we detect the loop and print a error message, continuing the decoding that is fated to fail. Will be cleaner to abort the decoding early. Propagate the error code to cedrus_device_run() and reset hardware on the cedrus_h265_skip_bits() failure. Suggested-by: Jernej Škrabec Signed-off-by: Dmitry Osipenko --- drivers/staging/media/sunxi/cedrus/cedrus_dec.c | 2 ++ drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 15 ++++++++++++--- drivers/staging/media/sunxi/cedrus/cedrus_hw.c | 7 ++++++- drivers/staging/media/sunxi/cedrus/cedrus_hw.h | 2 ++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_dec.c b/drivers/staging/media/sunxi/cedrus/cedrus_dec.c index e7f7602a5ab4..ae5df3dc01c0 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_dec.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_dec.c @@ -112,6 +112,8 @@ void cedrus_device_run(void *priv) dev->dec_ops[ctx->current_codec]->trigger(ctx); } else { + cedrus_hw_reset(dev); + v4l2_m2m_buf_done_and_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx, VB2_BUF_STATE_ERROR); diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c index 4952fc17f3e6..f409f59452d8 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c @@ -224,9 +224,10 @@ static void cedrus_h265_pred_weight_write(struct cedrus_dev *dev, } } -static void cedrus_h265_skip_bits(struct cedrus_dev *dev, int num) +static int cedrus_h265_skip_bits(struct cedrus_dev *dev, int num) { int count = 0; + int err; while (count < num) { int tmp = min(num - count, 32); @@ -235,11 +236,16 @@ static void cedrus_h265_skip_bits(struct cedrus_dev *dev, int num) VE_DEC_H265_TRIGGER_FLUSH_BITS | VE_DEC_H265_TRIGGER_TYPE_N_BITS(tmp)); - if (cedrus_wait_for(dev, VE_DEC_H265_STATUS, VE_DEC_H265_STATUS_VLD_BUSY)) + err = cedrus_wait_for(dev, VE_DEC_H265_STATUS, VE_DEC_H265_STATUS_VLD_BUSY); + if (err) { dev_err_ratelimited(dev->dev, "timed out waiting to skip bits\n"); + return err; + } count += tmp; } + + return 0; } static void cedrus_h265_write_scaling_list(struct cedrus_ctx *ctx, @@ -408,6 +414,7 @@ static int cedrus_h265_setup(struct cedrus_ctx *ctx, struct cedrus_run *run) u32 pic_order_cnt[2]; u8 *padding; int count; + int err; u32 reg; sps = run->h265.sps; @@ -534,7 +541,9 @@ static int cedrus_h265_setup(struct cedrus_ctx *ctx, struct cedrus_run *run) /* Include the one bit. */ count++; - cedrus_h265_skip_bits(dev, slice_params->data_byte_offset * 8 - count); + err = cedrus_h265_skip_bits(dev, slice_params->data_byte_offset * 8 - count); + if (err) + return err; /* Bitstream parameters. */ diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_hw.c b/drivers/staging/media/sunxi/cedrus/cedrus_hw.c index a6470a89851e..e9ceca332062 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_hw.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_hw.c @@ -168,11 +168,16 @@ void cedrus_watchdog(struct work_struct *work) VB2_BUF_STATE_ERROR); } +void cedrus_hw_reset(struct cedrus_dev *dev) +{ + reset_control_reset(dev->rstc); +} + int cedrus_hw_suspend(struct device *device) { struct cedrus_dev *dev = dev_get_drvdata(device); - reset_control_assert(dev->rstc); + cedrus_hw_reset(dev); clk_disable_unprepare(dev->ram_clk); clk_disable_unprepare(dev->mod_clk); diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_hw.h b/drivers/staging/media/sunxi/cedrus/cedrus_hw.h index 7c92f00e36da..919c4475f0d7 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_hw.h +++ b/drivers/staging/media/sunxi/cedrus/cedrus_hw.h @@ -30,4 +30,6 @@ void cedrus_hw_remove(struct cedrus_dev *dev); void cedrus_watchdog(struct work_struct *work); +void cedrus_hw_reset(struct cedrus_dev *dev); + #endif -- 2.37.3