Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp1518470rwj; Sun, 18 Dec 2022 09:42:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf7xE3V7J/atGNN/2TM+jX8d1qnbEV8ZTyR86/CV+3w6Ul824M/0V9hab/LbNxAirb48hG55 X-Received: by 2002:a05:6a21:108f:b0:ac:26cd:df30 with SMTP id nl15-20020a056a21108f00b000ac26cddf30mr39999686pzb.20.1671385377879; Sun, 18 Dec 2022 09:42:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671385377; cv=none; d=google.com; s=arc-20160816; b=nWVaIeEI04qC0n49566FmJEmGpPZ0eeqb6dlmoYyD5R/RneLnf8Qfmy53EI2jLwDX+ qZI+BQSQODJt67RCMNQf6WWdqpbZig/NSocpChNrdt1BegLaqZwRQt46TPli22dxR9Rj nlfOWOR2Oa44qDf3GFrRUFeMjfzd/DJuVWGozl3NRnZYnbXyTada7e2hJPAgipTNQIJN lnaq24adbaJeCbbPbISsxoB5yNXtCZDrwTd4Cl7OxbvotCv+qWl67BqgMrHGafifAzsT r+Qxa8UFHV85FU2k9SeXi8rf93ZWZxUs032JIKiPE5reP/sqszkVAdJ83vBgEaNugKf0 YGVA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rhybVsmpwSYKKlQK9DphfvFcIX5E+xgm/+I9Sy7jHlY=; b=Ksx7lVKyf98UHOajCyZMrAqFz4J0DnJR5u7+wRaU/q+H65HEqUIzJeP8TkBvom3jfc S/N4IiayBqyeRiiPR04HmfwMHSB/y9ra9cha0yLbOONjDTSEJXGD6RC5JKKlbT3N6LRX DgwX0zZj5zp8IAy5mJFuMJEEec5xr1/SxHr1m/Uclga6ixe6jeySr4qVZdGTmeAw0/Sg fykMcFUSLuEKTAOtJpFbSSH4FxnQPSXea/px+wQcnFJNUI3YHrnFqQYBAHR8HzJT6gBU cbKShgen6thZCu77TFIr/n08cmYPBfdb4d7rcDlVnrvUn876b+Wzm4OHIBvfqP2Q43w0 HM1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gJYguurI; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i62-20020a638741000000b004600f27528fsi8587882pge.175.2022.12.18.09.42.44; Sun, 18 Dec 2022 09:42:57 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=gJYguurI; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232651AbiLRQnW (ORCPT + 70 others); Sun, 18 Dec 2022 11:43:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232365AbiLRQki (ORCPT ); Sun, 18 Dec 2022 11:40:38 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D554BB87C; Sun, 18 Dec 2022 08:14:24 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 78B8EB803F1; Sun, 18 Dec 2022 16:14:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0EA3C433F1; Sun, 18 Dec 2022 16:14:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671380062; bh=35osr+OEI3kdIDPyeBIqzrkyNTESyWqL06yEem9qi40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gJYguurIeufuasAbLzlI+z1svN54p4OtdzNkswTMeMmTWM7Hi5/2J8AaD/t5QAhKR 94tR8EVxGcE16OmkeGWYgvIGzSVBpNw2HAq0dInQdh+y9tTcgdz7jcT9xQWnhit804 Dhe5xeZ7N8sUBnkswmzUDfPNKwmFLX+4q/YKsMqT6ESQg1ZHttmmeqeY4el8ihjH0o /gmyfuGb3aji/H7SigiuKUhVsHRYRSL1xT1Gpse/DHsg49A8/OjPYYXkryVl93geJW j/5Dnc4g2+eMRaeKM9EDOElhvruaQI1YEAGGr8cEcYxbBbpg35NHQ4LAEYxeWeibCH jGg8cqs5iZ7Kg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Sandy Huang , =?UTF-8?q?Heiko=20St=C3=BCbner?= , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, Daniel Vetter , Sasha Levin , airlied@gmail.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.15 22/46] drm/rockchip: Use drm_mode_copy() Date: Sun, 18 Dec 2022 11:12:20 -0500 Message-Id: <20221218161244.930785-22-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221218161244.930785-1-sashal@kernel.org> References: <20221218161244.930785-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 From: Ville Syrjälä [ Upstream commit 2bfaa28000d2830d3209161a4541cce0660e1b84 ] struct drm_display_mode embeds a list head, so overwriting the full struct with another one will corrupt the list (if the destination mode is on a list). Use drm_mode_copy() instead which explicitly preserves the list head of the destination mode. Even if we know the destination mode is not on any list using drm_mode_copy() seems decent as it sets a good example. Bad examples of not using it might eventually get copied into code where preserving the list head actually matters. Obviously one case not covered here is when the mode itself is embedded in a larger structure and the whole structure is copied. But if we are careful when copying into modes embedded in structures I think we can be a little more reassured that bogus list heads haven't been propagated in. @is_mode_copy@ @@ drm_mode_copy(...) { ... } @depends on !is_mode_copy@ struct drm_display_mode *mode; expression E, S; @@ ( - *mode = E + drm_mode_copy(mode, &E) | - memcpy(mode, E, S) + drm_mode_copy(mode, E) ) @depends on !is_mode_copy@ struct drm_display_mode mode; expression E; @@ ( - mode = E + drm_mode_copy(&mode, &E) | - memcpy(&mode, E, S) + drm_mode_copy(&mode, E) ) @@ struct drm_display_mode *mode; @@ - &*mode + mode Signed-off-by: Ville Syrjälä Cc: Sandy Huang Cc: "Heiko Stübner" Cc: linux-arm-kernel@lists.infradead.org Cc: linux-rockchip@lists.infradead.org Link: https://patchwork.freedesktop.org/patch/msgid/20221107192545.9896-7-ville.syrjala@linux.intel.com Reviewed-by: Daniel Vetter Signed-off-by: Sasha Levin --- drivers/gpu/drm/rockchip/cdn-dp-core.c | 2 +- drivers/gpu/drm/rockchip/inno_hdmi.c | 2 +- drivers/gpu/drm/rockchip/rk3066_hdmi.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/rockchip/cdn-dp-core.c b/drivers/gpu/drm/rockchip/cdn-dp-core.c index 6b5d0722afa6..20e63cadec8c 100644 --- a/drivers/gpu/drm/rockchip/cdn-dp-core.c +++ b/drivers/gpu/drm/rockchip/cdn-dp-core.c @@ -565,7 +565,7 @@ static void cdn_dp_encoder_mode_set(struct drm_encoder *encoder, video->v_sync_polarity = !!(mode->flags & DRM_MODE_FLAG_NVSYNC); video->h_sync_polarity = !!(mode->flags & DRM_MODE_FLAG_NHSYNC); - memcpy(&dp->mode, adjusted, sizeof(*mode)); + drm_mode_copy(&dp->mode, adjusted); } static bool cdn_dp_check_link_status(struct cdn_dp_device *dp) diff --git a/drivers/gpu/drm/rockchip/inno_hdmi.c b/drivers/gpu/drm/rockchip/inno_hdmi.c index 7afdc54eb3ec..78120da5e63a 100644 --- a/drivers/gpu/drm/rockchip/inno_hdmi.c +++ b/drivers/gpu/drm/rockchip/inno_hdmi.c @@ -488,7 +488,7 @@ static void inno_hdmi_encoder_mode_set(struct drm_encoder *encoder, inno_hdmi_setup(hdmi, adj_mode); /* Store the display mode for plugin/DPMS poweron events */ - memcpy(&hdmi->previous_mode, adj_mode, sizeof(hdmi->previous_mode)); + drm_mode_copy(&hdmi->previous_mode, adj_mode); } static void inno_hdmi_encoder_enable(struct drm_encoder *encoder) diff --git a/drivers/gpu/drm/rockchip/rk3066_hdmi.c b/drivers/gpu/drm/rockchip/rk3066_hdmi.c index 1c546c3a8998..17e7c40a9e7b 100644 --- a/drivers/gpu/drm/rockchip/rk3066_hdmi.c +++ b/drivers/gpu/drm/rockchip/rk3066_hdmi.c @@ -383,7 +383,7 @@ rk3066_hdmi_encoder_mode_set(struct drm_encoder *encoder, struct rk3066_hdmi *hdmi = to_rk3066_hdmi(encoder); /* Store the display mode for plugin/DPMS poweron events. */ - memcpy(&hdmi->previous_mode, adj_mode, sizeof(hdmi->previous_mode)); + drm_mode_copy(&hdmi->previous_mode, adj_mode); } static void rk3066_hdmi_encoder_enable(struct drm_encoder *encoder) -- 2.35.1