Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp1473018rwj; Sun, 18 Dec 2022 08:52:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf7fOqMSimynvut4A7iRh27JZ/Zbp7/bln95ZnWJUXpNl63zKtkBdM8VMzqTonrzhRg8snJP X-Received: by 2002:a17:906:7754:b0:78d:f455:b5c1 with SMTP id o20-20020a170906775400b0078df455b5c1mr33739220ejn.1.1671382347063; Sun, 18 Dec 2022 08:52:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671382347; cv=none; d=google.com; s=arc-20160816; b=QwHo3xffCL385Y5MN5zFMMwWK/+gF/mYgUerWP4YZYx8a3vJBTtvVRoxURiYKaEBUM Wb6qZsei/aDb13DOnDhh1KOEO+RbuuFx7WiK6a8FE3tmKJgZaQO8fwNgUB8JWVWJ6ghJ S9QKq7T9sz2ElsPVw10KmhO2nZWlIpos+PuALbGc75NK4jiBf96QyVUQsK2eQHEwldL6 relh8KHSnhXUZY9wlC55CQuQ+l801iXOBU24dfoHqO8Nl1RD1e20eMgkO2L/qrZHsrb6 aAf/+1UogdtMRJNPNl5gj6Qim5RTNNnsuZIJ1TEp+T97X7+GpFtrNd0+YvNd6SWlXtdo iWsw== 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=NfE3UEpMo2yg7DCm5JBDBxQV1wYnXsQFrZ9ZDFDTLMM=; b=IMt0cvg/4ykKFwb4a3wHU9kK/QQtl394Z44XEcM6rJqsV5bvxT8Kq5GokXmWIT1Lty vTVwdFuaUWnwQRdJPrVaEH+gXJp6ZSWxBnTqTsafM6y4qWebKYZc0nrObsGYFiOV/XaV UQMmyWcbot5XA3lCxhs11JNXoInab6a+afxmNz/Jm0tIBaklFiBU0uZ2ReOpR5yKbG9C 6LZdkIHOW2qZXql083WLsIskB+f5mucyY2TUeA1529x+DVJKleJXDXfl/elRDC08ErsQ CBsK8Qxs3glnkoIcHm7laGEOBB/Z013lh+sBBnWc5Tb9F4a5K3XDRFRtDnPz9AN0F5hB TVVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="fvehDGN/"; 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 hu9-20020a170907a08900b0077d854aa10dsi8144980ejc.57.2022.12.18.08.52.10; Sun, 18 Dec 2022 08:52:27 -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="fvehDGN/"; 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 S232596AbiLRQlq (ORCPT + 70 others); Sun, 18 Dec 2022 11:41:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232535AbiLRQks (ORCPT ); Sun, 18 Dec 2022 11:40:48 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EAD6B85A; Sun, 18 Dec 2022 08:14:26 -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 56D3DB80BD9; Sun, 18 Dec 2022 16:14:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F07FC433EF; Sun, 18 Dec 2022 16:14:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671380064; bh=OfI4N7rIhNn9ZClqz9Fr5bAcdf0yaK2plHOaKndVAM0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fvehDGN/jcLvtKiKyRAy+ZyIcT2nYQ//iz1eDQCFdL26Da087orBDjEyz+BaOu49F L7yoROWB4Zo50NnWw8MQh2ZoO3p2PUl4Duipphwir7GsQawSyW4b/B9JfDUoAgT9U7 G/Dbc8arcK1c5P7zJ9iaiTotQC1Qzpy3qNPSZlZaQ+UKKLMK9Dd1meevfGYCYNe8aY ZFkew7B8tWep8jiGaWFquXa34pmdikEGM/Gbb3fhFyg6KYabdH9xutrSgMZjONqw0U HjfDsNWX4wkmXsqyzoT2gSpX8/dJ7+802BgRqVVdjD/c9VrpJ6BnM0ptN9DQGq2482 r1698Sr/1Qf3A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Alain Volmat , Daniel Vetter , Sasha Levin , airlied@gmail.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.15 23/46] drm/sti: Use drm_mode_copy() Date: Sun, 18 Dec 2022 11:12:21 -0500 Message-Id: <20221218161244.930785-23-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 442cf8e22ba25a77cb9092d78733fdbac9844e50 ] 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 Cc: Alain Volmat Signed-off-by: Ville Syrjälä Link: https://patchwork.freedesktop.org/patch/msgid/20221107192545.9896-8-ville.syrjala@linux.intel.com Reviewed-by: Daniel Vetter Signed-off-by: Sasha Levin --- drivers/gpu/drm/sti/sti_dvo.c | 2 +- drivers/gpu/drm/sti/sti_hda.c | 2 +- drivers/gpu/drm/sti/sti_hdmi.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/sti/sti_dvo.c b/drivers/gpu/drm/sti/sti_dvo.c index b6ee8a82e656..f3a5616b7daf 100644 --- a/drivers/gpu/drm/sti/sti_dvo.c +++ b/drivers/gpu/drm/sti/sti_dvo.c @@ -288,7 +288,7 @@ static void sti_dvo_set_mode(struct drm_bridge *bridge, DRM_DEBUG_DRIVER("\n"); - memcpy(&dvo->mode, mode, sizeof(struct drm_display_mode)); + drm_mode_copy(&dvo->mode, mode); /* According to the path used (main or aux), the dvo clocks should * have a different parent clock. */ diff --git a/drivers/gpu/drm/sti/sti_hda.c b/drivers/gpu/drm/sti/sti_hda.c index 03f3377f918c..c9e6db15ab66 100644 --- a/drivers/gpu/drm/sti/sti_hda.c +++ b/drivers/gpu/drm/sti/sti_hda.c @@ -523,7 +523,7 @@ static void sti_hda_set_mode(struct drm_bridge *bridge, DRM_DEBUG_DRIVER("\n"); - memcpy(&hda->mode, mode, sizeof(struct drm_display_mode)); + drm_mode_copy(&hda->mode, mode); if (!hda_get_mode_idx(hda->mode, &mode_idx)) { DRM_ERROR("Undefined mode\n"); diff --git a/drivers/gpu/drm/sti/sti_hdmi.c b/drivers/gpu/drm/sti/sti_hdmi.c index f3ace11209dd..bb2a2868de2d 100644 --- a/drivers/gpu/drm/sti/sti_hdmi.c +++ b/drivers/gpu/drm/sti/sti_hdmi.c @@ -940,7 +940,7 @@ static void sti_hdmi_set_mode(struct drm_bridge *bridge, DRM_DEBUG_DRIVER("\n"); /* Copy the drm display mode in the connector local structure */ - memcpy(&hdmi->mode, mode, sizeof(struct drm_display_mode)); + drm_mode_copy(&hdmi->mode, mode); /* Update clock framerate according to the selected mode */ ret = clk_set_rate(hdmi->clk_pix, mode->clock * 1000); -- 2.35.1