Skip to content

Commit 9506fba

Browse files
nirmoyjnikula
authored andcommitted
drm/i915/tc: Fix -Wformat-truncation in intel_tc_port_init
Fix below compiler warning: intel_tc.c:1879:11: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 3 [-Werror=format-truncation=] "%c/TC#%d", port_name(port), tc_port + 1); ^~ intel_tc.c:1878:2: note: ‘snprintf’ output between 7 and 17 bytes into a destination of size 8 snprintf(tc->port_name, sizeof(tc->port_name), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "%c/TC#%d", port_name(port), tc_port + 1); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ v2: use kasprintf(Imre) v3: use const for port_name, and fix tc mem leak(Imre) Fixes: 3eafcdd ("drm/i915/tc: Move TC port fields to a new intel_tc_port struct") Cc: Mika Kahola <[email protected]> Cc: Imre Deak <[email protected]> Cc: Jani Nikula <[email protected]> Signed-off-by: Nirmoy Das <[email protected]> Reviewed-by: Andrzej Hajda <[email protected]> Reviewed-by: Imre Deak <[email protected]> Reviewed-by: Mika Kahola <[email protected]> Signed-off-by: Jani Nikula <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit 70a3cbb) Signed-off-by: Jani Nikula <[email protected]>
1 parent 1a8e9ba commit 9506fba

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/gpu/drm/i915/display/intel_tc.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct intel_tc_port {
5858
struct delayed_work link_reset_work;
5959
int link_refcount;
6060
bool legacy_port:1;
61-
char port_name[8];
61+
const char *port_name;
6262
enum tc_port_mode mode;
6363
enum tc_port_mode init_mode;
6464
enum phy_fia phy_fia;
@@ -1875,8 +1875,12 @@ int intel_tc_port_init(struct intel_digital_port *dig_port, bool is_legacy)
18751875
else
18761876
tc->phy_ops = &icl_tc_phy_ops;
18771877

1878-
snprintf(tc->port_name, sizeof(tc->port_name),
1879-
"%c/TC#%d", port_name(port), tc_port + 1);
1878+
tc->port_name = kasprintf(GFP_KERNEL, "%c/TC#%d", port_name(port),
1879+
tc_port + 1);
1880+
if (!tc->port_name) {
1881+
kfree(tc);
1882+
return -ENOMEM;
1883+
}
18801884

18811885
mutex_init(&tc->lock);
18821886
/* TODO: Combine the two works */
@@ -1897,6 +1901,7 @@ void intel_tc_port_cleanup(struct intel_digital_port *dig_port)
18971901
{
18981902
intel_tc_port_suspend(dig_port);
18991903

1904+
kfree(dig_port->tc->port_name);
19001905
kfree(dig_port->tc);
19011906
dig_port->tc = NULL;
19021907
}

0 commit comments

Comments
 (0)