From patchwork Thu Jul 27 15:56:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 710009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBEBBC0015E for ; Thu, 27 Jul 2023 15:57:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232274AbjG0P5M (ORCPT ); Thu, 27 Jul 2023 11:57:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231586AbjG0P5L (ORCPT ); Thu, 27 Jul 2023 11:57:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DE5730C2 for ; Thu, 27 Jul 2023 08:56:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690473380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=yNIprgBPbgBlUDGou/Q61G2MdeSraQtmRjGJ2xeLiJE=; b=Lj7punyIVr1RilDbuf3FL+vRuHd8bHLandPCr10zncqDm1qkR58yHIe12hCb1DX7W+Q3P4 ETS/BeB4Qx4MDAA7T+8Lw9VA1q9j1HfUJENINrzyiCd75HF8bVk0Iesn8fWtxICzbIjZxn /ZoKOPVKFuhIt97ayX1ntcq+r6Pp2pY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-150-s5J4NZuGNQapyiUgsPbyJQ-1; Thu, 27 Jul 2023 11:56:17 -0400 X-MC-Unique: s5J4NZuGNQapyiUgsPbyJQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 901E8802A55; Thu, 27 Jul 2023 15:56:16 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C655492B02; Thu, 27 Jul 2023 15:56:14 +0000 (UTC) From: Hans de Goede To: Mauro Carvalho Chehab , Sakari Ailus , Andy Shevchenko Cc: Hans de Goede , Kate Hsuan , Tsuchiya Yuto , Yury Luneff , Nable , andrey.i.trufanov@gmail.com, Fabio Aiuto , linux-media@vger.kernel.org, linux-staging@lists.linux.dev, Hans Verkuil Subject: [PATCH] media: atomisp: Fix smatch warnings caused by atomisp custom assert() usage Date: Thu, 27 Jul 2023 17:56:06 +0200 Message-ID: <20230727155606.41903-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The atomisp code base has a custom assert() macro, a couple of functions use this in a construction like the following: assert(pipe); assert(pipe->stream); if ((!pipe) || (!pipe->stream)) { ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, "allocate_mipi_frames(%p) exit: ...\n", pipe); return -EINVAL; } The second assert is seen by smatch as dereferencing "pipe" in the above example (and dereferencing "dvs_6axis_config" / "me" in the 2 other cases). Following by the dereferenced variable being checked (a second time) in the following if () statement. This triggers the following smatch warnings: drivers/staging/media/atomisp/pci/sh_css_mipi.c:356 allocate_mipi_frames() warn: variable dereferenced before check 'pipe' (see line 355) drivers/staging/media/atomisp/pci/sh_css_mipi.c:562 send_mipi_frames() warn: variable dereferenced before check 'pipe' (see line 561) drivers/staging/media/atomisp/pci/sh_css_param_dvs.c:208 free_dvs_6axis_table() warn: variable dereferenced before check 'dvs_6axis_config' (see line 206) drivers/staging/media/atomisp/pci/sh_css_sp.c:1255 sh_css_sp_init_pipeline() warn: variable dereferenced before check 'me->stages' (see line 1224) The custom assert() macro actually expands to a BUG() call and BUG() calls should not be used in the kernel. Remove the assert() calls to fix the smatch warnings and in case of [allocate|send]_mipi_frames() also remove the if () return -EINVAL block since these functions are never called with a NULL pipe. Reported-by: Hans Verkuil Signed-off-by: Hans de Goede --- Note: 1. No Closes: tag since Hans Verkuil reported this in an offlist email. 2. All the other assert() calls really should also be removed. I've put this on my todo list. --- drivers/staging/media/atomisp/pci/sh_css_mipi.c | 16 ---------------- .../staging/media/atomisp/pci/sh_css_param_dvs.c | 3 --- drivers/staging/media/atomisp/pci/sh_css_sp.c | 4 ---- 3 files changed, 23 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/sh_css_mipi.c b/drivers/staging/media/atomisp/pci/sh_css_mipi.c index b20acaab0595..ced21dedf7ac 100644 --- a/drivers/staging/media/atomisp/pci/sh_css_mipi.c +++ b/drivers/staging/media/atomisp/pci/sh_css_mipi.c @@ -351,15 +351,6 @@ allocate_mipi_frames(struct ia_css_pipe *pipe, ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, "allocate_mipi_frames(%p) enter:\n", pipe); - assert(pipe); - assert(pipe->stream); - if ((!pipe) || (!pipe->stream)) { - ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, - "allocate_mipi_frames(%p) exit: pipe or stream is null.\n", - pipe); - return -EINVAL; - } - if (IS_ISP2401 && pipe->stream->config.online) { ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, "allocate_mipi_frames(%p) exit: no buffers needed for 2401 pipe mode.\n", @@ -557,13 +548,6 @@ send_mipi_frames(struct ia_css_pipe *pipe) IA_CSS_ENTER_PRIVATE("pipe=%p", pipe); - assert(pipe); - assert(pipe->stream); - if (!pipe || !pipe->stream) { - IA_CSS_ERROR("pipe or stream is null"); - return -EINVAL; - } - /* multi stream video needs mipi buffers */ /* nothing to be done in other cases. */ if (pipe->stream->config.mode != IA_CSS_INPUT_MODE_BUFFERED_SENSOR) { diff --git a/drivers/staging/media/atomisp/pci/sh_css_param_dvs.c b/drivers/staging/media/atomisp/pci/sh_css_param_dvs.c index ff0082d02af3..5174bc210ae1 100644 --- a/drivers/staging/media/atomisp/pci/sh_css_param_dvs.c +++ b/drivers/staging/media/atomisp/pci/sh_css_param_dvs.c @@ -202,9 +202,6 @@ generate_dvs_6axis_table_from_config(struct ia_css_dvs_6axis_config void free_dvs_6axis_table(struct ia_css_dvs_6axis_config **dvs_6axis_config) { - assert(dvs_6axis_config); - assert(*dvs_6axis_config); - if ((dvs_6axis_config) && (*dvs_6axis_config)) { IA_CSS_ENTER_PRIVATE("dvs_6axis_config %p", (*dvs_6axis_config)); if ((*dvs_6axis_config)->xcoords_y) { diff --git a/drivers/staging/media/atomisp/pci/sh_css_sp.c b/drivers/staging/media/atomisp/pci/sh_css_sp.c index 4ef1c9e61ea8..5ecc982ad725 100644 --- a/drivers/staging/media/atomisp/pci/sh_css_sp.c +++ b/drivers/staging/media/atomisp/pci/sh_css_sp.c @@ -1215,10 +1215,6 @@ sh_css_sp_init_pipeline(struct ia_css_pipeline *me, unsigned int thread_id; u8 if_config_index, tmp_if_config_index; - assert(me); - - assert(me->stages); - first_binary = me->stages->binary; if (input_mode == IA_CSS_INPUT_MODE_SENSOR ||