'msg' is only used with drm_dp_encode_sideband_req() which takes a
"const struct drm_dp_sideband_msg_req_body *".

So some initializations can be done only once outside of the for loop.

Signed-off-by: Christophe JAILLET <christophe.jail...@wanadoo.fr>
---
In case of interest, on x86_64, with allmodconfig, sizeof(*msg) is 420
bytes.
---
 drivers/gpu/drm/display/drm_dp_mst_topology.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/display/drm_dp_mst_topology.c 
b/drivers/gpu/drm/display/drm_dp_mst_topology.c
index 7bf6157eb3a3..a149ff3f70ad 100644
--- a/drivers/gpu/drm/display/drm_dp_mst_topology.c
+++ b/drivers/gpu/drm/display/drm_dp_mst_topology.c
@@ -5891,10 +5891,16 @@ static int drm_dp_mst_i2c_write(struct 
drm_dp_mst_branch *mstb,
                ret = -ENOMEM;
                goto out;
        }
+
+       /*
+        * 'msg' is not modified by drm_dp_encode_sideband_req(). So
+        * some initializations can be done only once.
+        */
+       memset(&msg, 0, sizeof(msg));
+       msg.req_type = DP_REMOTE_I2C_WRITE;
+       msg.u.i2c_write.port_number = port->port_num;
+
        for (i = 0; i < num; i++) {
-               memset(&msg, 0, sizeof(msg));
-               msg.req_type = DP_REMOTE_I2C_WRITE;
-               msg.u.i2c_write.port_number = port->port_num;
                msg.u.i2c_write.write_i2c_device_id = msgs[i].addr;
                msg.u.i2c_write.num_bytes = msgs[i].len;
                msg.u.i2c_write.bytes = msgs[i].buf;
-- 
2.45.2

Reply via email to