From patchwork Fri Apr 26 23:58:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13645482 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AC2F2C4345F for ; Fri, 26 Apr 2024 23:59:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9CCC71125BE; Fri, 26 Apr 2024 23:59:12 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="hmZx+ujD"; dkim-atps=neutral Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by gabe.freedesktop.org (Postfix) with ESMTPS id E40871125BD for ; Fri, 26 Apr 2024 23:59:08 +0000 (UTC) Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-5c66b093b86so2862953a12.0 for ; Fri, 26 Apr 2024 16:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714175947; x=1714780747; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yeW0pSyEBhS0ojeIyWBVzu7M8GLRFtARAotr9ut3TYg=; b=hmZx+ujDG3mfGzhSQJN80pvNU0oc6Ic6DQkvvbTjVnyHXL3LYv4Oup9xfVn7DOb28+ P6NXv5BDO+lg9PP6UZxS3ZONz0KJ9UUEZnmaCgiW9NIfpjRyLDZzz3IkLBW1ttjDIKqg pNHY9/rkEUTKd9qNaUeUj8kmswyKFtWspUFEc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714175947; x=1714780747; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yeW0pSyEBhS0ojeIyWBVzu7M8GLRFtARAotr9ut3TYg=; b=ds02tykz68ebEMz90STlRplVUksdI2wkcEC3JZtYioYuOhhBdZISem7k8eSpwbRJG4 4EheBJq9sLkEy5EfBxiXRp8KOJf4+WrdC76I3Q+CiOmfZeVqJRxzWVUQS4FMTZXAmpON BnoJ4+6DfsPJoSCFQ5MLc7WcaeauK+DDefvPm0q63CVJiXuNJcg0xPTZ5whwn9iqfaBb 6j8rNht7ulroeRdy6JMfDK9r2aqNTMCwQyQyAwBmhoZRWTismPdp28xUzkcCef23TXI+ i5w+/A6UTWDEhK+9zbX7nh0BJKRjrrkkBepdrWmGbdKV66+6w4AV7KZQv97yTIu8obMv lE0w== X-Gm-Message-State: AOJu0YyJUGeV2jEDBSA47lBKxFDW+vc6mUz85A3TlYdPvs9MhegyukWR Qin0o+JvPkpHOhdXXsSfHTOh/hoCCaq7ZCyBCYTyGWT+eWVHtzZZ2bniz8EonyN2U+fsG+BBHmw = X-Google-Smtp-Source: AGHT+IH6XTJ9QQDWPzgo8X8I8bDLXm7/WGqdQG4aZWPTMylSuC2+pMH0ddw57O7ZuDywVmWBbG/TSg== X-Received: by 2002:a17:90a:1f88:b0:2aa:8130:e3eb with SMTP id x8-20020a17090a1f8800b002aa8130e3ebmr1501128pja.11.1714175946787; Fri, 26 Apr 2024 16:59:06 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:fca:3ae2:20e6:82bb]) by smtp.gmail.com with ESMTPSA id n4-20020a17090aab8400b002af41bd563esm5111939pjq.33.2024.04.26.16.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 16:59:06 -0700 (PDT) From: Douglas Anderson To: dri-devel@lists.freedesktop.org Cc: Linus Walleij , lvzhaoxiong@huaqin.corp-partner.google.com, Jani Nikula , Hsin-Yi Wang , Javier Martinez Canillas , Neil Armstrong , Joel Selvaraj , Dmitry Baryshkov , Cong Yang , Sam Ravnborg , Douglas Anderson , Daniel Vetter , David Airlie , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/8] drm/mipi-dsi: Fix theoretical int overflow in mipi_dsi_dcs_write_seq() Date: Fri, 26 Apr 2024 16:58:34 -0700 Message-ID: <20240426165839.v2.1.I30fa4c8348ea316c886ef8a522a52fed617f930d@changeid> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog In-Reply-To: <20240426235857.3870424-1-dianders@chromium.org> References: <20240426235857.3870424-1-dianders@chromium.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The mipi_dsi_dcs_write_seq() macro makes a call to mipi_dsi_dcs_write_buffer() which returns a type ssize_t. The macro then stores it in an int and checks to see if it's negative. This could theoretically be a problem if "ssize_t" is larger than "int". To see the issue, imagine that "ssize_t" is 32-bits and "int" is 16-bits, you could see a problem if there was some code out there that looked like: mipi_dsi_dcs_write_seq(dsi, cmd, <32767 bytes as arguments>); ...since we'd get back that 32768 bytes were transferred and 32768 stored in a 16-bit int would look negative. Though there are no callsites where we'd actually hit this (even if "int" was only 16-bit), it's cleaner to make the types match so let's fix it. Fixes: 2a9e9daf7523 ("drm/mipi-dsi: Introduce mipi_dsi_dcs_write_seq macro") Signed-off-by: Douglas Anderson --- Changes in v2: - New include/drm/drm_mipi_dsi.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h index 82b1cc434ea3..b3576be22bfa 100644 --- a/include/drm/drm_mipi_dsi.h +++ b/include/drm/drm_mipi_dsi.h @@ -337,12 +337,12 @@ int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, do { \ static const u8 d[] = { cmd, seq }; \ struct device *dev = &dsi->dev; \ - int ret; \ + ssize_t ret; \ ret = mipi_dsi_dcs_write_buffer(dsi, d, ARRAY_SIZE(d)); \ if (ret < 0) { \ dev_err_ratelimited( \ dev, "sending command %#02x failed: %d\n", \ - cmd, ret); \ + cmd, (int)ret); \ return ret; \ } \ } while (0)