Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp589689ybm; Wed, 27 May 2020 03:09:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLNxcHW1xhC4aT4dZwEDlV2nsFAaFvb54h7X1w3/iH+9LivpuSkmy2mwufFXrK7lKLIwIg X-Received: by 2002:a17:906:4353:: with SMTP id z19mr5553163ejm.371.1590574179692; Wed, 27 May 2020 03:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590574179; cv=none; d=google.com; s=arc-20160816; b=HfQZkcXPTzW9ez7tBlxnMLW5d42gZD/go1jN3IUHRVvTIRXDBlgEKtEJexCKyjqCyg lfggLdRVvHp6NZAoteBWFAtcQRkDvhk+58LkNh5UNepYdnK5LttnCZ4WPtkBiZYEyvlg HXYLzuN17RocNt/S9KhseFdV7p+LvbJtJ7epZXPVElleeGFk9QdB/Egrm2O5L29fXk8Z boftzdfgdgWiGPU0A6VtW8ZSEb+5csaO4JWOpspbCJc9qpGaAT8s0f0LjTmN2wJGHVGy pJPx/vJs7PjwcUrutPKgGEyzLEDoTkXTfi0nZAJ2BtQ/Yh3Z0tAwjGercgMwJpwOSa05 q3/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Tbgdqd+TXdAk8QNQkvpAeStL9yrt3nZfFNT/1PFaGls=; b=A/jUyZVt8g5tXgtoLg8I0K0M/431tR5QxuKC2jegMK9rB0cuBnknC4fhyHGQPSMGtt wPRrrugMaa/zjPM8P6N0+1PJLoezhXgKVFXTQjOFe4CHSOfP+NqdeQSG9L1xFq+wUKAH vKT098i6e+5258hUizbB8tX+y9PM1BSQg2Zq4cxa0SRYnX3tLNKmYPZFXlZyAaeVVi7z DfGGtlSuKX3hCF5mYfslI/xL3P4s9LNdbexvIkFHf1jPuaWDWrrS+/PPP6cFdu9/EZrf s3fUk0XshDlTRWjk7tlHN1O/inq05S0YV6Zx2EFaRh9uyhHET/BOfz9Ik1vQadQ2nvMa 8s5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=k1qgL0z6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t26si1710095ejt.612.2020.05.27.03.09.17; Wed, 27 May 2020 03:09:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=k1qgL0z6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729188AbgE0HM1 (ORCPT + 99 others); Wed, 27 May 2020 03:12:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729151AbgE0HMW (ORCPT ); Wed, 27 May 2020 03:12:22 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23F10C061A0F; Wed, 27 May 2020 00:12:22 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id d10so11370231pgn.4; Wed, 27 May 2020 00:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Tbgdqd+TXdAk8QNQkvpAeStL9yrt3nZfFNT/1PFaGls=; b=k1qgL0z6SiL5RJ1jy1ddTv2tly55L3zXvSGIJ+d1Q8l14IIWnU8jdo/ew4J/MGZ1a1 ghhp01Z2ro6ZZW20+RGtLXPi4dzOcPrC5WNO8MTcS3Bgp+gvUyu/hj2LrSIZjOZ0Trc3 IqDmuUKZZtuZ6g73xrRk3FBEWp6nqRS7HyxoMZFLM5w+X/RQoi6fPntepT9EBWnM6Jig doZXNjAdevq31/+HN5f/EnFXd/8pj6dfnCNgGsSmeuBxuiopt7x2NIrxPpGnLz+2CtiS j810vjU2dvanzhLIukM3tlZDPZSv+/KOeBVqFZTQtzfYghYrcWM1AseG/12XCcrjs2Yn i87Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Tbgdqd+TXdAk8QNQkvpAeStL9yrt3nZfFNT/1PFaGls=; b=pH1wonvy7KciVwNuT1GW2BzOxNlBmV/FAct2avVovkWyAgLgohtQ23ID+5aYV9SCnE uH9bqlFPxFGYjqMufPVbKTf6Edi9JbHzcqXwkcwJvGQ4J6BSsrvWTmQBKTMsJtY2mkQQ D9HV12HC01sSGSvpHxhi5tsQgCuVq+1se+Mj6QPgfnthqkULLbMCgq2g7U0EwWjeFM4v p1Ew+t9Ln+Zs+wfrfP7KXFvYT4n2N6VOEafsCj21nRF6LP0jmMLIQExkWArKyIMRQpQs mZuEXYIWs+hhb3fhuGSkLuBMlq6rAkLukngidBSz4YSPhqv+KZP99cunYjwwlkW5zziG SHQg== X-Gm-Message-State: AOAM531OfpjLsi0DYmxd9YxidZy5uLMzFAk55562q/Pbbbne1JeIOuEY 3VTAzQK20ymRPIGMK3E/y1w= X-Received: by 2002:a63:78b:: with SMTP id 133mr2796179pgh.161.1590563541617; Wed, 27 May 2020 00:12:21 -0700 (PDT) Received: from localhost.localdomain ([2604:1380:4111:8b00::1]) by smtp.gmail.com with ESMTPSA id 10sm1306431pfx.138.2020.05.27.00.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 00:12:21 -0700 (PDT) From: Nathan Chancellor To: Mauro Carvalho Chehab Cc: Sakari Ailus , linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, Nathan Chancellor Subject: [PATCH 6/7] media: atomisp: Avoid overflow in compute_blending Date: Wed, 27 May 2020 00:11:49 -0700 Message-Id: <20200527071150.3381228-7-natechancellor@gmail.com> X-Mailer: git-send-email 2.27.0.rc0 In-Reply-To: <20200527071150.3381228-1-natechancellor@gmail.com> References: <20200527071150.3381228-1-natechancellor@gmail.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Clang warns: drivers/staging/media/atomisp/pci/isp/kernels/xnr/xnr_3.0/ia_css_xnr3.host.c:129:35: warning: implicit conversion from 'unsigned long' to 'int32_t' (aka 'int') changes value from 18446744073709543424 to -8192 [-Wconstant-conversion] return MAX(MIN(isp_strength, 0), -XNR_BLENDING_SCALE_FACTOR); ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ XNR_BLENDING_SCALE_FACTOR is BIT(13), or 8192, which will easily fit into a signed 32-bit integer. However, it is an unsigned long, which means that negating it is the same as subtracting that value from ULONG_MAX + 1, which causes it to be larger than a signed 32-bit integer so it gets implicitly converted. We can avoid this by using the variable isp_scale, which holds the value of XNR_BLENDING_SCALE_FACTOR already, where the implicit conversion from unsigned long to s32 already happened. If that were to ever overflow, clang would warn: https://godbolt.org/z/EeSxLG Link: https://github.com/ClangBuiltLinux/linux/issues/1036 Signed-off-by: Nathan Chancellor --- .../atomisp/pci/isp/kernels/xnr/xnr_3.0/ia_css_xnr3.host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/media/atomisp/pci/isp/kernels/xnr/xnr_3.0/ia_css_xnr3.host.c b/drivers/staging/media/atomisp/pci/isp/kernels/xnr/xnr_3.0/ia_css_xnr3.host.c index a9db6366d20b..629f07faf20a 100644 --- a/drivers/staging/media/atomisp/pci/isp/kernels/xnr/xnr_3.0/ia_css_xnr3.host.c +++ b/drivers/staging/media/atomisp/pci/isp/kernels/xnr/xnr_3.0/ia_css_xnr3.host.c @@ -126,7 +126,7 @@ compute_blending(int strength) * exactly as s0.11 fixed point, but -1.0 can. */ isp_strength = -(((strength * isp_scale) + offset) / host_scale); - return MAX(MIN(isp_strength, 0), -XNR_BLENDING_SCALE_FACTOR); + return MAX(MIN(isp_strength, 0), -isp_scale); } void -- 2.27.0.rc0