diff mbox series

[v2] drm/i915/tc: Fix -Wformat-truncation in intel_tc_port_init

Message ID 20231025170834.22691-1-nirmoy.das@intel.com (mailing list archive)
State New, archived
Headers show
Series [v2] drm/i915/tc: Fix -Wformat-truncation in intel_tc_port_init | expand

Commit Message

Nirmoy Das Oct. 25, 2023, 5:08 p.m. UTC
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)

Fixes: 3eafcddf766b ("drm/i915/tc: Move TC port fields to a new intel_tc_port struct")
Cc: Mika Kahola <mika.kahola@intel.com>
Cc: Imre Deak <imre.deak@intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Nirmoy Das <nirmoy.das@intel.com>
---
 drivers/gpu/drm/i915/display/intel_tc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Andrzej Hajda Oct. 25, 2023, 6:54 p.m. UTC | #1
On 25.10.2023 19:08, Nirmoy Das wrote:
> 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)
> 
> Fixes: 3eafcddf766b ("drm/i915/tc: Move TC port fields to a new intel_tc_port struct")
> Cc: Mika Kahola <mika.kahola@intel.com>
> Cc: Imre Deak <imre.deak@intel.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> Signed-off-by: Nirmoy Das <nirmoy.das@intel.com>

Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>

Regards
Andrzej

> ---
>   drivers/gpu/drm/i915/display/intel_tc.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_tc.c b/drivers/gpu/drm/i915/display/intel_tc.c
> index 37b0f8529b4f..0fa54450d51b 100644
> --- a/drivers/gpu/drm/i915/display/intel_tc.c
> +++ b/drivers/gpu/drm/i915/display/intel_tc.c
> @@ -58,7 +58,7 @@ struct intel_tc_port {
>   	struct delayed_work link_reset_work;
>   	int link_refcount;
>   	bool legacy_port:1;
> -	char port_name[8];
> +	char *port_name;
>   	enum tc_port_mode mode;
>   	enum tc_port_mode init_mode;
>   	enum phy_fia phy_fia;
> @@ -1875,8 +1875,10 @@ int intel_tc_port_init(struct intel_digital_port *dig_port, bool is_legacy)
>   	else
>   		tc->phy_ops = &icl_tc_phy_ops;
>   
> -	snprintf(tc->port_name, sizeof(tc->port_name),
> -		 "%c/TC#%d", port_name(port), tc_port + 1);
> +	tc->port_name = kasprintf(GFP_KERNEL, "%c/TC#%d", port_name(port),
> +				  tc_port + 1);
> +	if (!tc->port_name)
> +		return -ENOMEM;
>   
>   	mutex_init(&tc->lock);
>   	/* TODO: Combine the two works */
> @@ -1897,6 +1899,7 @@ void intel_tc_port_cleanup(struct intel_digital_port *dig_port)
>   {
>   	intel_tc_port_suspend(dig_port);
>   
> +	kfree(dig_port->tc->port_name);
>   	kfree(dig_port->tc);
>   	dig_port->tc = NULL;
>   }
Imre Deak Oct. 26, 2023, 9:05 a.m. UTC | #2
On Wed, Oct 25, 2023 at 07:08:34PM +0200, Nirmoy Das wrote:
> 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)
> 
> Fixes: 3eafcddf766b ("drm/i915/tc: Move TC port fields to a new intel_tc_port struct")
> Cc: Mika Kahola <mika.kahola@intel.com>
> Cc: Imre Deak <imre.deak@intel.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> Signed-off-by: Nirmoy Das <nirmoy.das@intel.com>

Reviewed-by: Imre Deak <imre.deak@intel.com>

Nit: port_name could be const.

> ---
>  drivers/gpu/drm/i915/display/intel_tc.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_tc.c b/drivers/gpu/drm/i915/display/intel_tc.c
> index 37b0f8529b4f..0fa54450d51b 100644
> --- a/drivers/gpu/drm/i915/display/intel_tc.c
> +++ b/drivers/gpu/drm/i915/display/intel_tc.c
> @@ -58,7 +58,7 @@ struct intel_tc_port {
>  	struct delayed_work link_reset_work;
>  	int link_refcount;
>  	bool legacy_port:1;
> -	char port_name[8];
> +	char *port_name;
>  	enum tc_port_mode mode;
>  	enum tc_port_mode init_mode;
>  	enum phy_fia phy_fia;
> @@ -1875,8 +1875,10 @@ int intel_tc_port_init(struct intel_digital_port *dig_port, bool is_legacy)
>  	else
>  		tc->phy_ops = &icl_tc_phy_ops;
>  
> -	snprintf(tc->port_name, sizeof(tc->port_name),
> -		 "%c/TC#%d", port_name(port), tc_port + 1);
> +	tc->port_name = kasprintf(GFP_KERNEL, "%c/TC#%d", port_name(port),
> +				  tc_port + 1);
> +	if (!tc->port_name)
> +		return -ENOMEM;
>  
>  	mutex_init(&tc->lock);
>  	/* TODO: Combine the two works */
> @@ -1897,6 +1899,7 @@ void intel_tc_port_cleanup(struct intel_digital_port *dig_port)
>  {
>  	intel_tc_port_suspend(dig_port);
>  
> +	kfree(dig_port->tc->port_name);
>  	kfree(dig_port->tc);
>  	dig_port->tc = NULL;
>  }
> -- 
> 2.41.0
>
Imre Deak Oct. 26, 2023, 10:11 a.m. UTC | #3
On Thu, Oct 26, 2023 at 12:05:13PM +0300, Imre Deak wrote:
> On Wed, Oct 25, 2023 at 07:08:34PM +0200, Nirmoy Das wrote:
> > 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)
> > 
> > Fixes: 3eafcddf766b ("drm/i915/tc: Move TC port fields to a new intel_tc_port struct")
> > Cc: Mika Kahola <mika.kahola@intel.com>
> > Cc: Imre Deak <imre.deak@intel.com>
> > Cc: Jani Nikula <jani.nikula@intel.com>
> > Signed-off-by: Nirmoy Das <nirmoy.das@intel.com>
> 
> Reviewed-by: Imre Deak <imre.deak@intel.com>
> 
> Nit: port_name could be const.
> 
> > ---
> >  drivers/gpu/drm/i915/display/intel_tc.c | 9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/display/intel_tc.c b/drivers/gpu/drm/i915/display/intel_tc.c
> > index 37b0f8529b4f..0fa54450d51b 100644
> > --- a/drivers/gpu/drm/i915/display/intel_tc.c
> > +++ b/drivers/gpu/drm/i915/display/intel_tc.c
> > @@ -58,7 +58,7 @@ struct intel_tc_port {
> >  	struct delayed_work link_reset_work;
> >  	int link_refcount;
> >  	bool legacy_port:1;
> > -	char port_name[8];
> > +	char *port_name;
> >  	enum tc_port_mode mode;
> >  	enum tc_port_mode init_mode;
> >  	enum phy_fia phy_fia;
> > @@ -1875,8 +1875,10 @@ int intel_tc_port_init(struct intel_digital_port *dig_port, bool is_legacy)
> >  	else
> >  		tc->phy_ops = &icl_tc_phy_ops;
> >  
> > -	snprintf(tc->port_name, sizeof(tc->port_name),
> > -		 "%c/TC#%d", port_name(port), tc_port + 1);
> > +	tc->port_name = kasprintf(GFP_KERNEL, "%c/TC#%d", port_name(port),
> > +				  tc_port + 1);
> > +	if (!tc->port_name)
> > +		return -ENOMEM;

Missed it, but this needs to free tc;

> >  
> >  	mutex_init(&tc->lock);
> >  	/* TODO: Combine the two works */
> > @@ -1897,6 +1899,7 @@ void intel_tc_port_cleanup(struct intel_digital_port *dig_port)
> >  {
> >  	intel_tc_port_suspend(dig_port);
> >  
> > +	kfree(dig_port->tc->port_name);
> >  	kfree(dig_port->tc);
> >  	dig_port->tc = NULL;
> >  }
> > -- 
> > 2.41.0
> >
Nirmoy Das Oct. 26, 2023, 10:15 a.m. UTC | #4
On 10/26/2023 12:11 PM, Imre Deak wrote:
> On Thu, Oct 26, 2023 at 12:05:13PM +0300, Imre Deak wrote:
>> On Wed, Oct 25, 2023 at 07:08:34PM +0200, Nirmoy Das wrote:
>>> 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)
>>>
>>> Fixes: 3eafcddf766b ("drm/i915/tc: Move TC port fields to a new intel_tc_port struct")
>>> Cc: Mika Kahola <mika.kahola@intel.com>
>>> Cc: Imre Deak <imre.deak@intel.com>
>>> Cc: Jani Nikula <jani.nikula@intel.com>
>>> Signed-off-by: Nirmoy Das <nirmoy.das@intel.com>
>> Reviewed-by: Imre Deak <imre.deak@intel.com>
>>
>> Nit: port_name could be const.
>>
>>> ---
>>>   drivers/gpu/drm/i915/display/intel_tc.c | 9 ++++++---
>>>   1 file changed, 6 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/i915/display/intel_tc.c b/drivers/gpu/drm/i915/display/intel_tc.c
>>> index 37b0f8529b4f..0fa54450d51b 100644
>>> --- a/drivers/gpu/drm/i915/display/intel_tc.c
>>> +++ b/drivers/gpu/drm/i915/display/intel_tc.c
>>> @@ -58,7 +58,7 @@ struct intel_tc_port {
>>>   	struct delayed_work link_reset_work;
>>>   	int link_refcount;
>>>   	bool legacy_port:1;
>>> -	char port_name[8];
>>> +	char *port_name;
>>>   	enum tc_port_mode mode;
>>>   	enum tc_port_mode init_mode;
>>>   	enum phy_fia phy_fia;
>>> @@ -1875,8 +1875,10 @@ int intel_tc_port_init(struct intel_digital_port *dig_port, bool is_legacy)
>>>   	else
>>>   		tc->phy_ops = &icl_tc_phy_ops;
>>>   
>>> -	snprintf(tc->port_name, sizeof(tc->port_name),
>>> -		 "%c/TC#%d", port_name(port), tc_port + 1);
>>> +	tc->port_name = kasprintf(GFP_KERNEL, "%c/TC#%d", port_name(port),
>>> +				  tc_port + 1);
>>> +	if (!tc->port_name)
>>> +		return -ENOMEM;
> Missed it, but this needs to free tc;

Oh, thanks for catching it.


Regards,

Nirmoy

>
>>>   
>>>   	mutex_init(&tc->lock);
>>>   	/* TODO: Combine the two works */
>>> @@ -1897,6 +1899,7 @@ void intel_tc_port_cleanup(struct intel_digital_port *dig_port)
>>>   {
>>>   	intel_tc_port_suspend(dig_port);
>>>   
>>> +	kfree(dig_port->tc->port_name);
>>>   	kfree(dig_port->tc);
>>>   	dig_port->tc = NULL;
>>>   }
>>> -- 
>>> 2.41.0
>>>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/display/intel_tc.c b/drivers/gpu/drm/i915/display/intel_tc.c
index 37b0f8529b4f..0fa54450d51b 100644
--- a/drivers/gpu/drm/i915/display/intel_tc.c
+++ b/drivers/gpu/drm/i915/display/intel_tc.c
@@ -58,7 +58,7 @@  struct intel_tc_port {
 	struct delayed_work link_reset_work;
 	int link_refcount;
 	bool legacy_port:1;
-	char port_name[8];
+	char *port_name;
 	enum tc_port_mode mode;
 	enum tc_port_mode init_mode;
 	enum phy_fia phy_fia;
@@ -1875,8 +1875,10 @@  int intel_tc_port_init(struct intel_digital_port *dig_port, bool is_legacy)
 	else
 		tc->phy_ops = &icl_tc_phy_ops;
 
-	snprintf(tc->port_name, sizeof(tc->port_name),
-		 "%c/TC#%d", port_name(port), tc_port + 1);
+	tc->port_name = kasprintf(GFP_KERNEL, "%c/TC#%d", port_name(port),
+				  tc_port + 1);
+	if (!tc->port_name)
+		return -ENOMEM;
 
 	mutex_init(&tc->lock);
 	/* TODO: Combine the two works */
@@ -1897,6 +1899,7 @@  void intel_tc_port_cleanup(struct intel_digital_port *dig_port)
 {
 	intel_tc_port_suspend(dig_port);
 
+	kfree(dig_port->tc->port_name);
 	kfree(dig_port->tc);
 	dig_port->tc = NULL;
 }