From patchwork Sat Jan 11 09:55:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13935977 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B78A18E03A for ; Sat, 11 Jan 2025 09:55:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736589326; cv=none; b=PdfhqzDo1xHBdFFOOk31W1+wYRE/rVvlRrIcUu5ps+cv3b5WxuidSQIuSxIkYQPncYlYJpCsVqbl0B8+4RSIzJ7CgS/m3saqsAdRMlN80XULDsN8bjVW1p3i2D8XaviGCUryn863AcQV1UkFmcl3gxGei6N0onJ/QKHaCTTTMlQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736589326; c=relaxed/simple; bh=cJ3Ao2R6zgoGJgyibADb5EAE6IKBeo/pElOZjlQDp0Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FclKEBgsWfd+yPd6h46IdyPf0ce4X9w0v5AYWEojp144qWjJfTyOsvuYOTNdQObFf2nnRO/3dFVFVVdDVzbOWJue1oYz5o+AtljrWS/EYCAxppm0MDqb8K4R+10JDpjUpuqmJAj7fFqn3BzAxBmxus6jcjVeAIwRJQMU7Tjr5sw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=OuMYyroZ; arc=none smtp.client-ip=209.85.219.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="OuMYyroZ" Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-6dfbc45355bso2023126d6.2 for ; Sat, 11 Jan 2025 01:55:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1736589324; x=1737194124; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=52iWgPg8zx+q33hKer1CkCPQAZHddOV8vj+q0ZyeQAY=; b=OuMYyroZ54iH3H6THbYRxENeEoSEm6U9dF9xpWxmLlRUSPh2Ze2UF+ZOeCuX+s/OKM wnDnthyOIuTqks1c+0lB8q7kVXqGtBxV2xi8rJMwDWMTZd+T9KBlxHodSFZuIlK+g83u A1KZ1Mz1rf1NnH+dkinadBwAmyVmx7LRXFlbg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736589324; x=1737194124; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=52iWgPg8zx+q33hKer1CkCPQAZHddOV8vj+q0ZyeQAY=; b=N4gp7O8//6JXc50tOYA1nAXxJNrn6XELbqBVU32Rua/w+ScDM9HN21QfrgFtmt5ASZ B5II8h0JFwRGpCR+wCY9WlWfKgbHhvsWmUt3LdAryMrRfvZ8lY3tkpqhJWzCG+GL/Ie7 ZniNM31uqLK9hhPCUmAlX6yxBOA0Gzfr8Ikq2dhCOyWFtfSTp039SC4k0pRvZ6tIG70u PYOdLoX9mLpUe5Qb/MmheGMS7PMEms2QFbKCkVzPQC7VqH8KTFNeP0Z3qshRvTa09u/y bhRC3mz9FeUlexMDKfWUuMgrOVjvDtMq/p4lXqbbs/ll81n2/5gHTVPmq/8zIY0YCRtj 8acA== X-Gm-Message-State: AOJu0YzA2NaCo+k2/bsDwnF1wW7vFawJfyDkWauMRwHMFlIAxWYT0GTT NGy9ByKroFEDYparY0AMFrAV6+XLRheWedq/mfwasncyKiiRk0FgH8rhHzsnfDwxg8rJDpbTrG0 QaA== X-Gm-Gg: ASbGnctmTYa4Oi4vtYpoafxVoiFCBx9SG4STubOIq928EH03m13IzloJewUBrfFMRSC PrZ5TacgeftHMGe415hTtvNTCCP64JMMB46GeeVERJUKhduUIhUldggxrkUVYFfmDv9eOJNF9E/ LY1Chkt5XJAHKgWknFoQSHLkcqlAEs/7bhe8cwLNCSdNAcdYFWeifIzYxge9hWyfsh3grizW3SG +siLj3x0/9E2Avt4/0yv6x9XSDGxlys/HAjv/sf9V+4W8ccqsg6SzumdrNl3eVFAAxvOORB8sS0 4/yUchkYY2Ize+dQYhckrh2ji72T8ykeDw74 X-Google-Smtp-Source: AGHT+IFqiGK2VIMRcFvBZ2YyjvHmdtNauhF62df7aKlMfYRbakz7XnEj9n0FSoSywyG9ImyL+3sm3w== X-Received: by 2002:a05:6214:2a8f:b0:6d8:8e16:7c29 with SMTP id 6a1803df08f44-6df9b2383f5mr216932866d6.14.1736589324231; Sat, 11 Jan 2025 01:55:24 -0800 (PST) Received: from denia.c.googlers.com (172.174.245.35.bc.googleusercontent.com. [35.245.174.172]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7bce327b8besm267096785a.59.2025.01.11.01.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2025 01:55:23 -0800 (PST) From: Ricardo Ribalda Date: Sat, 11 Jan 2025 09:55:14 +0000 Subject: [PATCH v6 1/6] media: dvb-frontends: tda10048: Make the range of z explicit. Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250111-fix-cocci-v6-1-1aa7842006cc@chromium.org> References: <20250111-fix-cocci-v6-0-1aa7842006cc@chromium.org> In-Reply-To: <20250111-fix-cocci-v6-0-1aa7842006cc@chromium.org> To: Mauro Carvalho Chehab , Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Kosta Stefanov , Ricardo Ribalda X-Mailer: b4 0.13.0 The datasheet recommends 55MHz frequency sampling, with a max of 69 MHz. (Kudos to Kosta Stefanov for the calculations). Replace z with a 32 bit uint, and make the range of the variable explicit. Found by cocci: drivers/media/dvb-frontends/tda10048.c:345:1-7: WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead. Reviewed-by: Kosta Stefanov Signed-off-by: Ricardo Ribalda --- drivers/media/dvb-frontends/tda10048.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/media/dvb-frontends/tda10048.c b/drivers/media/dvb-frontends/tda10048.c index 3e725cdcc66b..1f87eb0dcf2a 100644 --- a/drivers/media/dvb-frontends/tda10048.c +++ b/drivers/media/dvb-frontends/tda10048.c @@ -328,7 +328,8 @@ static int tda10048_set_wref(struct dvb_frontend *fe, u32 sample_freq_hz, u32 bw) { struct tda10048_state *state = fe->demodulator_priv; - u64 t, z; + u64 t; + u32 z; dprintk(1, "%s()\n", __func__); @@ -341,6 +342,11 @@ static int tda10048_set_wref(struct dvb_frontend *fe, u32 sample_freq_hz, /* t *= 2147483648 on 32bit platforms */ t *= (2048 * 1024); t *= 1024; + + /* + * Sample frequency is typically 55 MHz, with a theoretical maximum of + * 69 MHz. With a 32 bit z we have enough accuracy for up to 613 MHz. + */ z = 7 * sample_freq_hz; do_div(t, z); t += 5; From patchwork Sat Jan 11 09:55:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13935978 Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C9B818FDAE for ; Sat, 11 Jan 2025 09:55:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736589329; cv=none; b=Wl6bpxqfrf8YqfcLH97BLifSe4g1KP20TxbExF8CZPKOOuDQdwzOU0KT+ppTfgxFX5Zv8m06AUPloP6qk8XIOesEwv5uJYyEECTtNw/u7V621TWdWUVmh2rwxUWGQ7oH9gVjdrZ9gKx6k+Twqw+WjP/OcBtVCbOwMjcPkRZjZuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736589329; c=relaxed/simple; bh=wNqPLVCH3hrYmgRdcOul7vFmT8NC6JPiLWWSYrAMGoA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m0XyAz5zi1BLRvgdkCc6VfI+tRiWW8SS4mCUmOyhiocERGbvDlV2K3iuoq3Tx1bH2j17h3D713sbh3+arZEiefEF4WNnJckfFs0YYE+3FshNApbYgooAtD+DEu97Byufvy3C+ooDTXMXi5v5jR3CMkDFq7tqFE6PIDF4BZ+VAWk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=mzmvtG/6; arc=none smtp.client-ip=209.85.219.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="mzmvtG/6" Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-6d8e8445219so24168086d6.0 for ; Sat, 11 Jan 2025 01:55:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1736589327; x=1737194127; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=oCQd+Ixr8eKIqoAvIvPqynaVVvGYXfmfSE/3mmNL7HE=; b=mzmvtG/6r8mK1zoH6VyrK6+xwRRAqfawlkHIsMszsUYLwvRYn/6TL6Qr61/nvx8rAs Gdd6cw9NSir9g7J/HgO8xO7qrQTrxXDEXPVfhXpquWrhuvR6ClZz03Lm7piHlXl+HFPd BDIm1RO4GnaeoAduoXWkj5W/YsYTt8+q8gCHY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736589327; x=1737194127; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oCQd+Ixr8eKIqoAvIvPqynaVVvGYXfmfSE/3mmNL7HE=; b=kmZx8Sv6S88AAzB8b/8R7KCcyTH+MvZBe8yBjdWLXVv4rbdN3z5qpSyyoNMQqiBiZ4 +HK5IJJo3r0NpmHrx8DxBGTAGetzzUIYCpmBycY3TjMFwHrD4vL3QEJvCoWvwzqRee+s qMt4sm8fg8Q8tyzdSvtFRyDmw+CDQGKBaGtL+IkEJrVDY1MhYNr2OWRH1ibyk7mYqHHl QNqJpEWC2b7Ky9mmRmXtH4+0Ge7PYX58njdlT1S71vPf27tnltYf9sk14eSnj0cPHlix 28IkgbzazXMoQG2T/7KZfHS6+R4O5ej4G1L+ZqPQGtF6MxqupEMg74LOiYdk1Vcf+gA5 4LEw== X-Gm-Message-State: AOJu0YwvQt565NIxw1x7WXfU54gBeqrtkF4B5XkwCKs7rAsC+Hor30Ea S9pF4OZbf6iWpnY2IVBUse9HOuo1slfDS+OI0s9g7RYESPfO8E/Av6+z9LmsXA== X-Gm-Gg: ASbGncu+tNSqwa/gYsiRMfFB6saGwaLCrl3xEcfy8Bjq+6cgTRWpODznTNtf9vM/ywk gAitoQKu224aHEv7QxzhFpjzQaWg+mWpU1VLuJm4nhO9TPUFlWPD+4SEnr0zO0zWxCggxWvqNkg Rti+/93fO2U88FihUDrz518NZBZSHs3oL6krnkIR3RnT7igIOi4KGShFrih8IV6uapK46Ohm8Mq HOJ+UHhSgztFXS9RzXKIX1a86US0tiEVyswYhy3U+iyxUrzU0hDH9XVFX6XRxY1eRiG0zz2xoQs Glj9kH/xRGyDoNUFPeoiHIatXZRj46JURID7 X-Google-Smtp-Source: AGHT+IHefNcjGKIvCVrBMfxFKkoA1dyzaoWQ3H4EQvH1E/W+4lJXoiyaYADeYG3+4FMKAC4ihgK0qA== X-Received: by 2002:a05:6214:4111:b0:6d8:8416:9c54 with SMTP id 6a1803df08f44-6df9b1ed60bmr244663736d6.16.1736589326457; Sat, 11 Jan 2025 01:55:26 -0800 (PST) Received: from denia.c.googlers.com (172.174.245.35.bc.googleusercontent.com. [35.245.174.172]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7bce327b8besm267096785a.59.2025.01.11.01.55.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2025 01:55:25 -0800 (PST) From: Ricardo Ribalda Date: Sat, 11 Jan 2025 09:55:15 +0000 Subject: [PATCH v6 2/6] media: venus: vdec: Clamp parm smaller than 1fps and bigger than 240. Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250111-fix-cocci-v6-2-1aa7842006cc@chromium.org> References: <20250111-fix-cocci-v6-0-1aa7842006cc@chromium.org> In-Reply-To: <20250111-fix-cocci-v6-0-1aa7842006cc@chromium.org> To: Mauro Carvalho Chehab , Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 The driver uses "whole" fps in all its calculations (e.g. in load_per_instance()). Those calculation expect an fps bigger than 1, and not big enough to overflow. Clamp the value if the user provides a parm that will result in an invalid fps. Reported-by: Hans Verkuil Closes: https://lore.kernel.org/linux-media/f11653a7-bc49-48cd-9cdb-1659147453e4@xs4all.nl/T/#m91cd962ac942834654f94c92206e2f85ff7d97f0 Fixes: 7472c1c69138 ("[media] media: venus: vdec: add video decoder files") Signed-off-by: Ricardo Ribalda Tested-by: Bryan O'Donoghue # qrb5615-rb5 Reviewed-by: Bryan O'Donoghue --- drivers/media/platform/qcom/venus/core.h | 2 ++ drivers/media/platform/qcom/venus/vdec.c | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h index 44f1c3bc4186..afae2b9fdaf7 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -28,6 +28,8 @@ #define VIDC_RESETS_NUM_MAX 2 #define VIDC_MAX_HIER_CODING_LAYER 6 +#define VENUS_MAX_FPS 240 + extern int venus_fw_debug; struct freq_tbl { diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c index 98c22b9f9372..c1d5f94e16b4 100644 --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -481,11 +481,10 @@ static int vdec_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a) us_per_frame = timeperframe->numerator * (u64)USEC_PER_SEC; do_div(us_per_frame, timeperframe->denominator); - if (!us_per_frame) - return -EINVAL; - + us_per_frame = max(USEC_PER_SEC, us_per_frame); fps = (u64)USEC_PER_SEC; do_div(fps, us_per_frame); + fps = min(VENUS_MAX_FPS, fps); inst->fps = fps; inst->timeperframe = *timeperframe; From patchwork Sat Jan 11 09:55:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13935979 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A1C41917FB for ; Sat, 11 Jan 2025 09:55:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736589331; cv=none; b=tm7MtdlUzqNyxCtRR3FuPK2Xj1i6ycfpLnX8AU4RF82/hblqKArWg6G/fbuL7Uv1K7vv/XLdBhIFek1wKzgj7KhI+zmgVHXzwfb+Jp7pm/A/dJ9DGDT2vS9niYD+GPzNJIQM5tEauv9GAjS0gz7yznz4XgEclAsXGHiVXmpPEfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736589331; c=relaxed/simple; bh=+5gKBR6lmCbLgDxwlcOKTLF2APbAil9sB0eDtQkBz/w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZvXiVAPiCqKfIIN4+2yqRTLQFAflD9kDxPoJZ3hESdelDm4271ifPuKzH45WzZOZt4WsuYcC1+G36nlsgykF+feIyDQ0HHI/P+uuqUX5vedjC5U6V6jbBDAXsKD8/ojfcLYT/5/rw1X2GXqv5WrGNXUutfakkcMtFuGQBrG70ds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=C96bSz6T; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="C96bSz6T" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7b70e78351aso236813185a.0 for ; Sat, 11 Jan 2025 01:55:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1736589328; x=1737194128; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=oGXizJerOok0lDZxPeMPfVFSvShgmDlyLJgvxCS81kE=; b=C96bSz6TaoQXqnsfWjFREu7KcD0EjOj6CbbnAHPSV2wqMTwI6pYbppEnh56C8ciRLt H/6p4gZMwGnmmDFNwcYC9KGNozEAzwSgg1WjdQioFifHmeBNay88+Q2Nqm16gdQZszcM ZX50gFtVpauN4oFNajPz3VpJMepN/dQNUDEQk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736589328; x=1737194128; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oGXizJerOok0lDZxPeMPfVFSvShgmDlyLJgvxCS81kE=; b=u58iY3OI0bRWGxIoQYJlJitmUXcPZkJ/ZKxerDYVxyu5X1DcUHTRS1wwQpkaA+AjFk xCmyLmWptgRaQo/Fw//x2EkwQOX95Dl+SCIw0IDoZXl1vIOSrr3KgPbu/Si0ZAim4oFm nQx6Cht5Hft64H8f6CsZijCFGpvIWgnwsY52DcfBQVkammEv2EnUYYweHsBo0EpN0xCh mMaWweMT6KnLek+M2H2AyNA554ervclzO8BH1GDz3QapSW28QTS+E5Vyd4h5XMF3IVl3 veNVprWNsiyXb9p/Cfap4riU17WcNNPn4MlmM6gPnCYxo6gAE46k1Q2oix5KdUmD3n2O P4lw== X-Gm-Message-State: AOJu0YxDIThtmPzlcoplXUK0oHPqBZ34kGhTzPWR7cLo5/H75DVx8gEF mS23fvjbXa3+yie25EA8LHa1M53IDA6QmM37USKLkfzcFgjXWtkVPq3N7KRP1A== X-Gm-Gg: ASbGncv8xw+Wz+2mSDPsM//lRgX+UfbsOtgRFPIPZ8QttXHdg4RkMSdo1ILFs5RuD5u XWXm17kKKJEJNMvrqOs00XebBMJRSOQTN5zfnYiFXVHZTZiHp8XxJkONNAuRi+e1zHn6YDrqDLQ 4CWaI0Mc16T5zQ2XltG4QOXLLrzkUCw0Q/cytk1OJQOMIAd3+kev5A3KsE/96/z7ZxdZ1X5ZAek 6bvSY8+rwrgW9AucaBBdzvzKV0G64cCk8T0Hyf567ip4+YGamTBPbgIAZ7UOUoQ8KjLCmA7SOfG EpOz5GYYtJg6bhhEJ9il2CyNuJ6+fl+GyY/b X-Google-Smtp-Source: AGHT+IEpVR9I5biYuCr+SXV0UBeBGfKSe31bfLKgP7VOr+BuuQiGS7W1xlNlsmHP///j6pnH4LIVBQ== X-Received: by 2002:a05:620a:462b:b0:7b6:c540:9531 with SMTP id af79cd13be357-7bcd974a281mr2043337685a.18.1736589328570; Sat, 11 Jan 2025 01:55:28 -0800 (PST) Received: from denia.c.googlers.com (172.174.245.35.bc.googleusercontent.com. [35.245.174.172]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7bce327b8besm267096785a.59.2025.01.11.01.55.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2025 01:55:27 -0800 (PST) From: Ricardo Ribalda Date: Sat, 11 Jan 2025 09:55:16 +0000 Subject: [PATCH v6 3/6] media: venus: venc: Clamp parm smaller than 1fps and bigger than 240 Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250111-fix-cocci-v6-3-1aa7842006cc@chromium.org> References: <20250111-fix-cocci-v6-0-1aa7842006cc@chromium.org> In-Reply-To: <20250111-fix-cocci-v6-0-1aa7842006cc@chromium.org> To: Mauro Carvalho Chehab , Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 The driver uses "whole" fps in all its calculations (e.g. in load_per_instance()). Those calculation expect an fps bigger than 1, and not big enough to overflow. Clamp the parm if the user provides a value that will result in an invalid fps. Reported-by: Hans Verkuil Closes: https://lore.kernel.org/linux-media/f11653a7-bc49-48cd-9cdb-1659147453e4@xs4all.nl/T/#m91cd962ac942834654f94c92206e2f85ff7d97f0 Fixes: aaaa93eda64b ("[media] media: venus: venc: add video encoder files") Signed-off-by: Ricardo Ribalda --- drivers/media/platform/qcom/venus/venc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c index c1c543535aaf..943d432b6568 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -411,11 +411,10 @@ static int venc_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a) us_per_frame = timeperframe->numerator * (u64)USEC_PER_SEC; do_div(us_per_frame, timeperframe->denominator); - if (!us_per_frame) - return -EINVAL; - + us_per_frame = max(USEC_PER_SEC, us_per_frame); fps = (u64)USEC_PER_SEC; do_div(fps, us_per_frame); + fps = min(VENUS_MAX_FPS, fps); inst->timeperframe = *timeperframe; inst->fps = fps; From patchwork Sat Jan 11 09:55:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13935980 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E3841922E0 for ; Sat, 11 Jan 2025 09:55:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736589334; cv=none; b=SVb1fBaQp3a3sIPSUmbTmBVhcE/kh1CB1hMiwMDfBBpP5NdLq9ZVv7oppL6GfkFsQ4cHHEEqBu/ZMwJxkYH0igZMhVhZrux/zuTCGcN/akQDhPXfmUYE0pi5xeY89rXrcNxz+UVhfXf+HC711okDX8VKl+29XnnaThz6cGpihRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736589334; c=relaxed/simple; bh=BHqXjzXegfvyleJbFzCIkEZ/Ohsk17MMdh8326GOkbU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LTueivF3vijgkYsC1rxbkjNOlHuIfaxZtxWFFKRuLA4aUlO34RQ/ZCcTq075/TCLzaJZ12DNdHnUCUIX6WmpDgAFqWDar+7iOfEBAA9uEj7VZKdJzsau73SBguCjS6h4gujHdSdmCRidv47uULQpLvqqIrMCd/NQ4pRApPmOAkE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=eCMys+aI; arc=none smtp.client-ip=209.85.222.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="eCMys+aI" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7b6e9db19c8so234044085a.3 for ; Sat, 11 Jan 2025 01:55:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1736589330; x=1737194130; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=L1KYqWnRc25c7X6AgX8mJMBcXv6X4I+XW042aps6zcs=; b=eCMys+aINUeyPpHOqwmcacUWkFZpKdFbU3ZRGl2lokoR4qr5aKpr4UDxLxbAkP0xhm W17GheV+iCuPMwLG3CEpQO/NQ1bwW2Q6OJzTb3cPHwjchTh3BfTxzkGoqiSEtI9FfXfO ck8Uj5y3NhBNhIllRRwxnAaPKwhiZJUhubre8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736589330; x=1737194130; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=L1KYqWnRc25c7X6AgX8mJMBcXv6X4I+XW042aps6zcs=; b=vi7xmIpuMSB0JvlUwOHEu6eKL+LwSLbOodn16unUJKMdUm3dUjs45T5aRsgvsChF/S D+3rJP2TreQvduBtj+xgYqM18a81sh97DYvDmNBoiXNU2mdsOsuWTfaXsz2ptKXk3kXr 1J0EuGax9yVdsroaGCZc+jB78gxSEw++8PjgHR8CM4iogV77ssCbvyBtP/ukfdLJerr5 Ydv8obcOPE0wiOallmpOVAP4rF6JHwS3fa/BSA2jxkxSLpc2NSvw8+mpqe3CnM9o4sSr udc/kP2vNlNqA4NKf4YsdsyXJ0LZ2VSSBg0jBWRXgkEYKnIntYlmX8377Kbmw5gcFUHL 80OQ== X-Gm-Message-State: AOJu0Yz7lqf/OkY8jWfws62orb7F/z96rXzS3Ojdz4UejQwRh/cxJRiv 9kbE7MorOIbHBcWolUW3hdQsm6FJUHoF91iyL6ExdnCwOIpIqACSei8jDhNT4Q== X-Gm-Gg: ASbGncvQybLpi9gmSPykEGV446OUsUeOusSSBIewNl/m53ZATeErJHDfEDBQmVWgEV5 TdDJWTNzYksYEAro7TPcv+19ylW1m47j/SAa/heYoabsNuWX4V7O9W/K4ohlkfjoL/Gyvc1JHAO W+zeb1QKeLQp6H8GpWe2rF53EWS5VLkLxpZjJrD2TSai3H5B3866f5pZJnO6W1pMIA+IX0NBq9b 0SyqfOyxhWFjpetJbnERjYTyahOnN57rGOHLY30VaXKZ1PjWXchC8DH3TeZcNCoHID05DBXgB3O 9gh4wuSVcp7yaWX3r2fGDoukkTEUSpBBOfMo X-Google-Smtp-Source: AGHT+IEPxC3OyMHAru8G3Gzds3v7OF/JkO9AvPzj8XxD1gntOl6n6mbYKW7VgLUWHJdUgNP6gB5oAA== X-Received: by 2002:a05:620a:4402:b0:7b6:d6dd:8826 with SMTP id af79cd13be357-7bcd97b8724mr2371667285a.55.1736589330581; Sat, 11 Jan 2025 01:55:30 -0800 (PST) Received: from denia.c.googlers.com (172.174.245.35.bc.googleusercontent.com. [35.245.174.172]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7bce327b8besm267096785a.59.2025.01.11.01.55.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2025 01:55:29 -0800 (PST) From: Ricardo Ribalda Date: Sat, 11 Jan 2025 09:55:17 +0000 Subject: [PATCH v6 4/6] media: venus: Remove timeperframe from inst Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250111-fix-cocci-v6-4-1aa7842006cc@chromium.org> References: <20250111-fix-cocci-v6-0-1aa7842006cc@chromium.org> In-Reply-To: <20250111-fix-cocci-v6-0-1aa7842006cc@chromium.org> To: Mauro Carvalho Chehab , Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 The driver only cares about whole fps. We can infer the timeperframe from the fps field. Remove the redundant field. Signed-off-by: Ricardo Ribalda --- drivers/media/platform/qcom/venus/core.h | 2 -- drivers/media/platform/qcom/venus/vdec.c | 15 ++++++++------- drivers/media/platform/qcom/venus/venc.c | 16 ++++++++-------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h index afae2b9fdaf7..1d4fd5cc75d9 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -407,7 +407,6 @@ enum venus_inst_modes { * @tss: timestamp metadata * @payloads: cache plane payload to use it for clock/BW scaling * @fps: holds current FPS - * @timeperframe: holds current time per frame structure * @fmt_out: a reference to output format structure * @fmt_cap: a reference to capture format structure * @num_input_bufs: holds number of input buffers @@ -478,7 +477,6 @@ struct venus_inst { struct venus_ts_metadata tss[VIDEO_MAX_FRAME]; unsigned long payloads[VIDEO_MAX_FRAME]; u64 fps; - struct v4l2_fract timeperframe; const struct venus_format *fmt_out; const struct venus_format *fmt_cap; unsigned int num_input_bufs; diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c index c1d5f94e16b4..e160a5508154 100644 --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -471,10 +471,12 @@ static int vdec_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a) return -EINVAL; memset(cap->reserved, 0, sizeof(cap->reserved)); - if (!timeperframe->denominator) - timeperframe->denominator = inst->timeperframe.denominator; - if (!timeperframe->numerator) - timeperframe->numerator = inst->timeperframe.numerator; + + if (!timeperframe->numerator || !timeperframe->denominator) { + timeperframe->numerator = 1; + timeperframe->denominator = inst->fps; + } + cap->readbuffers = 0; cap->extendedmode = 0; cap->capability = V4L2_CAP_TIMEPERFRAME; @@ -487,7 +489,8 @@ static int vdec_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a) fps = min(VENUS_MAX_FPS, fps); inst->fps = fps; - inst->timeperframe = *timeperframe; + timeperframe->numerator = 1; + timeperframe->denominator = inst->fps; return 0; } @@ -1612,8 +1615,6 @@ static void vdec_inst_init(struct venus_inst *inst) inst->out_width = frame_width_min(inst); inst->out_height = frame_height_min(inst); inst->fps = 30; - inst->timeperframe.numerator = 1; - inst->timeperframe.denominator = 30; inst->opb_buftype = HFI_BUFFER_OUTPUT; } diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c index 943d432b6568..17bec44c9825 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -401,10 +401,10 @@ static int venc_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a) memset(out->reserved, 0, sizeof(out->reserved)); - if (!timeperframe->denominator) - timeperframe->denominator = inst->timeperframe.denominator; - if (!timeperframe->numerator) - timeperframe->numerator = inst->timeperframe.numerator; + if (!timeperframe->numerator || !timeperframe->denominator) { + timeperframe->numerator = 1; + timeperframe->denominator = inst->fps; + } out->capability = V4L2_CAP_TIMEPERFRAME; @@ -416,8 +416,9 @@ static int venc_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a) do_div(fps, us_per_frame); fps = min(VENUS_MAX_FPS, fps); - inst->timeperframe = *timeperframe; inst->fps = fps; + timeperframe->numerator = 1; + timeperframe->denominator = inst->fps; return 0; } @@ -431,7 +432,8 @@ static int venc_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a) return -EINVAL; a->parm.output.capability |= V4L2_CAP_TIMEPERFRAME; - a->parm.output.timeperframe = inst->timeperframe; + a->parm.output.timeperframe.numerator = 1; + a->parm.output.timeperframe.denominator = inst->fps; return 0; } @@ -1454,8 +1456,6 @@ static void venc_inst_init(struct venus_inst *inst) inst->out_width = 1280; inst->out_height = 720; inst->fps = 15; - inst->timeperframe.numerator = 1; - inst->timeperframe.denominator = 15; inst->hfi_codec = HFI_VIDEO_CODEC_H264; } From patchwork Sat Jan 11 09:55:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13935981 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE041193409 for ; Sat, 11 Jan 2025 09:55:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736589335; cv=none; b=MXLM5US7VCT3IaEbQhcv4ReNQdvJbbMZZ4jtMFPTIsWIR6mC82ONz5GzT7xUqUtiZB7YTHC4pTtwBDD+7mergqslZ5uklJ4z+rOdLwikIlQ4RQhws+JkCMWNsiaTwum28eKw+dY95POui5ybVUm5VotDtMV81WJTrvoKYqSJeXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736589335; c=relaxed/simple; bh=jFMkE+aUW4A2Tjf06APpBG1sAvp2ejflRJ8B5s0jBLU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EvMylIobWCAbmJALgwYgx9hO65y7bFCdE8WSqM76rx6hs/wzGKEreoa2nLhjc9BkYVrMF7Yfgwxhc7RhCRCz6fzotun4c61ENoRsEb1JGwDaqWUsBCdzKjMb9ga28HAOUD4dqQwiJUSqHRE2ASgAkDAspbnURG99s5uW3Yp85zU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=bbKyHPHV; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="bbKyHPHV" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-7b85d5cc39eso299299585a.3 for ; Sat, 11 Jan 2025 01:55:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1736589333; x=1737194133; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=f3BoX2c5ZbHlzZ/xObQ8c1PFxHvs7MLN/22FFGinwVE=; b=bbKyHPHV+azn/fU4OTZ4UULuoo/8Wyomc7g3GS2WVI+rKoWrBv+wlq7KOXkn29VjqO IJEhnJ7jdxGh528esEr9B9DJsCQ3ro+yc5PLBqB5luxbq138kyLtWM+xFCrm954vwTmh tVQ66Er2TUZsKHcD7rKrUG6k1A18u9QTpPy4Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736589333; x=1737194133; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f3BoX2c5ZbHlzZ/xObQ8c1PFxHvs7MLN/22FFGinwVE=; b=pPlXV9fqlAvC0raBEJ5M0FAczhvS2J0m79f8d8dK4dngnlaB2nCxYt8yrIqKZ4HsyO c28UKOcRPIHHjrXmKN2tpXZCB5ODWei8FsXQqquytO+3hxqlTL+XwrG7OFSvKGtPjOjo E7WaRfckmelTUS9j2LA/LxiD3v+nAZXhcK4xN4RpYsD8SAr7QMv1z3O9PB3v0okKkNwh Iqz6ZQIl/ANk1bWmCGB91mI0kaH6oXfgLvkA+2Wrr2jPjPMlT3qoNozOTv30SHAyafUN 0baHbZYdAQ3jTXgNe4rapdJsMlWTn38XL6jNKt49ywgbg5Zd1sLBvsfWHGHzkRYcuWP0 yf8g== X-Gm-Message-State: AOJu0Yyr74lQz7niOQBJhkdAIvspWcbvGuvWzFapN2/ITmpVKZM6TjLh wTWYWk0DS4jT1TGSE3LA3QqT8OqVtnwxdkZeV6txlGuwIfJUJZ2WKtS/sr75Lg== X-Gm-Gg: ASbGncvBkDVVpf0gw5LWRZNkmRxNaqpgBPOgCMjJ0T9B/H3fjUMVbGzah/q5Fs0e/bt UqlYqf/rpizqG+zJwFr7OLeloMjlQW5FC2bMr4kXyH3yJ/wZuc6Qwpgak7jqQtB3SkrjOkbenWD H/Xwo6Q4xGo9Lu3EHvV/iNgmUgNJNydrzGGyNQGdxEU/P86L1d+Sivx6XGv1pXrR+Sj+oFerewB c9RyMGCM3jCz9CxZsVmpFhDyBwX9bV4mACyzTGqLEhW7MEpr6dVb+r0BbM3dJMH2aIDMJljzDNL Xyg99x34Nix8tpQcQd1LqdbkCgS9EzmuNvCO X-Google-Smtp-Source: AGHT+IHlflZapXB2U5EwdDsff9V9lka7ZWi7FvO7mOnx6N5gTF17d6mrdBuskWw0aArQ5dE890/KbQ== X-Received: by 2002:a05:620a:2481:b0:7b6:ece3:825d with SMTP id af79cd13be357-7bcd9726520mr1906864685a.12.1736589332721; Sat, 11 Jan 2025 01:55:32 -0800 (PST) Received: from denia.c.googlers.com (172.174.245.35.bc.googleusercontent.com. [35.245.174.172]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7bce327b8besm267096785a.59.2025.01.11.01.55.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2025 01:55:31 -0800 (PST) From: Ricardo Ribalda Date: Sat, 11 Jan 2025 09:55:18 +0000 Subject: [PATCH v6 5/6] media: venus: venc: Make the range of us_per_frame explicit Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250111-fix-cocci-v6-5-1aa7842006cc@chromium.org> References: <20250111-fix-cocci-v6-0-1aa7842006cc@chromium.org> In-Reply-To: <20250111-fix-cocci-v6-0-1aa7842006cc@chromium.org> To: Mauro Carvalho Chehab , Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 Fps bigger than 0.000232829 fps, this fits in a 32 bit us_per_frame. There is no need to do a 64 bit division here. Also, the driver only works with whole fps. Found with cocci: drivers/media/platform/qcom/venus/venc.c:418:1-7: WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead. Reviewed-by: Bryan O'Donoghue Signed-off-by: Ricardo Ribalda --- drivers/media/platform/qcom/venus/venc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c index 17bec44c9825..2c1836712362 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -412,8 +412,7 @@ static int venc_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a) do_div(us_per_frame, timeperframe->denominator); us_per_frame = max(USEC_PER_SEC, us_per_frame); - fps = (u64)USEC_PER_SEC; - do_div(fps, us_per_frame); + fps = USEC_PER_SEC / (u32)us_per_frame; fps = min(VENUS_MAX_FPS, fps); inst->fps = fps; From patchwork Sat Jan 11 09:55:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13935982 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A4D518FC89 for ; Sat, 11 Jan 2025 09:55:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736589347; cv=none; b=ckUwvalNbAyC4yZu1VDqKHaphWU50C9JC9lM1PfKskJTpy3fESw9WaD57FJZ36Eh5ORt3Vnq2sE8hmoGvKoLdIQR3i8+itWgmTVbHfOcEWrUU87SX4E7SjlKXigKMuxc+fXvt4aAn0xyI+pXGOMrhJZQoZ4E2Fx8RbBioTHbtqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736589347; c=relaxed/simple; bh=hAlPOuL4YIiXg0HpbIYhah7+pVVbm4tj/0Q43k0VF20=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QEiTd0bVF/ilWEC+5ChYBiOEArUm01K/tmy0CzYJAEpIL2zgA2suq6n4LvCtbyNkW1n73QzSOZWVoDE/pJYUb6m7SWaAOxqAIjZoc/IrhjLXshppegcNKZBkt/fRw0dtB+ZoaAvJaFPguVoP3fOaiZV+67gDL/JcxGhoB9tDWZw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=iSdlN1C0; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="iSdlN1C0" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-7b9ad0e84e6so281974385a.0 for ; Sat, 11 Jan 2025 01:55:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1736589345; x=1737194145; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=x7AhuqiCmj982Ah3x3XQKiIUQdsA0iVwLzLzuPzwXZk=; b=iSdlN1C0rGRnzvzQnMULxgVbw+tZymFS0zBYfHuPP8TMxo83WqVvB4UixO+VAxvbz2 0ChEh5pE4hOziKajDXj05dtstSe723KgbQrUMfEnVjvEEJAgYOODrKkMgpR7sdZMmW2V pZvGnB+SfNoWgq09RbTmkiHx65BOzFdglgjlg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736589345; x=1737194145; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x7AhuqiCmj982Ah3x3XQKiIUQdsA0iVwLzLzuPzwXZk=; b=J9Gw+rtFnNRr2Ney+UlKaSupfPLcb1LmyTKfBMmLhBfxpMsmNTn+ZBytNW70gdB3xD i2XxkDMJCyOBuVByYxKE2lKyVzusv72nBK95A280MWRXYEz6RY4Fe+gUNv7Bpl/r6HUS CzL4xy+JbhkNh0GCC5S2NAytubolrBfdislRwWTqhdZFnMvH5b/Ccbjyll0QtweUJLgl UaVXTiGoSTIHWf68esiRj+tqAEzLO2Oz+hXA9FaNtHQv8V3zTjf5ke271/Tctmfmft9+ 4tMtBPa0Kwd1ryL5B0MmkRx2U9HfqTdtlaqUVe39NxsAxjzV2sfZFHbD4lrZUuUoAtbZ RBHg== X-Gm-Message-State: AOJu0YxUWlYuCP4YixaO23Hnx6t2LUlnh+iiV0JJ3LHR/PyTgM4qV37u 6Za96p/X02R3Vmkp/lIEIDM/waMNUMRuPML2z+PlBzNQ9XddndyHbPedxLdWnzcof7PL97oWk4L RCg== X-Gm-Gg: ASbGncuEMWL+xzc29CbwnzDwemmD/QGzw0bug94mmEWGLHywx8uZIjmyjPS/fajGCft UWzDmT/gzwgs5KD+YGJHyeKG6emVOb9kKiM1jYXPISKKW0MHyWWI92vJDVK+8RcTBB8e9wNBIqz rS7/ujTZgdhAml08WLRlZGyU/HsZAsVs9FiVSCs/fP9rH4I5o7j4v6oeseLM2HketBldkG2gzL5 hBXhX+cFh3pREXnC4g6oTvq1Nd+Kru9Le5whofCF3pg/ODWfVP0HhQqiZY/Mn4IyWnp4lr7z4hP ra5m8YhMlEKCYvJQ5JtYYeWSMB2+1rJ6FdFK X-Google-Smtp-Source: AGHT+IFPc65u5Xb9RCjGLJ3Jl3Vf9y0Du5AsKFgmKuWXejd7Aufwu6k8jsIz9OTvYdbOGhoPzK7nZw== X-Received: by 2002:a05:620a:462c:b0:7b6:d0bd:c7e6 with SMTP id af79cd13be357-7bcd9759db8mr2313763885a.32.1736589334727; Sat, 11 Jan 2025 01:55:34 -0800 (PST) Received: from denia.c.googlers.com (172.174.245.35.bc.googleusercontent.com. [35.245.174.172]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7bce327b8besm267096785a.59.2025.01.11.01.55.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2025 01:55:33 -0800 (PST) From: Ricardo Ribalda Date: Sat, 11 Jan 2025 09:55:19 +0000 Subject: [PATCH v6 6/6] media: venus: vdec: Make the range of us_per_frame explicit Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250111-fix-cocci-v6-6-1aa7842006cc@chromium.org> References: <20250111-fix-cocci-v6-0-1aa7842006cc@chromium.org> In-Reply-To: <20250111-fix-cocci-v6-0-1aa7842006cc@chromium.org> To: Mauro Carvalho Chehab , Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 Fps bigger than 0.000232829 fps, this fits in a 32 bit us_per_frame. There is no need to do a 64 bit division here. Also, the driver only works with whole fps. Found by cocci: drivers/media/platform/qcom/venus/vdec.c:488:1-7: WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead. Reviewed-by: Bryan O'Donoghue Signed-off-by: Ricardo Ribalda Tested-by: Bryan O'Donoghue # qrb5615-rb5 Reviewed-by: Bryan O'Donoghue --- drivers/media/platform/qcom/venus/vdec.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c index e160a5508154..aa9ba38186b8 100644 --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -484,8 +484,7 @@ static int vdec_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a) do_div(us_per_frame, timeperframe->denominator); us_per_frame = max(USEC_PER_SEC, us_per_frame); - fps = (u64)USEC_PER_SEC; - do_div(fps, us_per_frame); + fps = USEC_PER_SEC / (u32)us_per_frame; fps = min(VENUS_MAX_FPS, fps); inst->fps = fps;