remoteproc: qcom: replace kstrdup with kstrndup

Message ID 1676383691-29738-1-git-send-email-quic_mojha@quicinc.com
State New
Headers
Series remoteproc: qcom: replace kstrdup with kstrndup |

Commit Message

Mukesh Ojha Feb. 14, 2023, 2:08 p.m. UTC
  Since, there is no guarantee that region.name will be 0-terminated
from the firmware side, replace kstrdup with kstrndup.

Suggested-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
---
 drivers/remoteproc/qcom_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Bjorn Andersson Feb. 14, 2023, 4:39 p.m. UTC | #1
On Tue, Feb 14, 2023 at 07:38:11PM +0530, Mukesh Ojha wrote:
> Since, there is no guarantee that region.name will be 0-terminated
> from the firmware side, replace kstrdup with kstrndup.
> 
> Suggested-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>

Please don't send additional patches in-reply-to another patch, it makes
it impossible to use b4 to pick up the first patch.

And please don't send two patches which clearly will conflict with
each other. Now I had to manually apply the first patch...

Regards,
Bjorn

> ---
>  drivers/remoteproc/qcom_common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/remoteproc/qcom_common.c b/drivers/remoteproc/qcom_common.c
> index 020349f..7810f91 100644
> --- a/drivers/remoteproc/qcom_common.c
> +++ b/drivers/remoteproc/qcom_common.c
> @@ -124,7 +124,7 @@ static int qcom_add_minidump_segments(struct rproc *rproc, struct minidump_subsy
>  	for (i = 0; i < seg_cnt; i++) {
>  		memcpy_fromio(&region, ptr + i, sizeof(region));
>  		if (region.valid == MD_REGION_VALID) {
> -			name = kstrdup(region.name, GFP_KERNEL);
> +			name = kstrndup(region.name, MAX_REGION_NAME_LENGTH - 1, GFP_KERNEL);
>  			if (!name) {
>  				iounmap(ptr);
>  				return -ENOMEM;
> -- 
> 2.7.4
>
  
Bjorn Andersson Feb. 14, 2023, 5:30 p.m. UTC | #2
On Tue, 14 Feb 2023 19:38:11 +0530, Mukesh Ojha wrote:
> Since, there is no guarantee that region.name will be 0-terminated
> from the firmware side, replace kstrdup with kstrndup.
> 
> 

Applied, thanks!

[1/1] remoteproc: qcom: replace kstrdup with kstrndup
      commit: 9d5b9ad97f83b2390a6006eeb5ae5e48ec4298ce

Best regards,
  
Mukesh Ojha Feb. 15, 2023, 5:16 a.m. UTC | #3
On 2/14/2023 10:09 PM, Bjorn Andersson wrote:
> On Tue, Feb 14, 2023 at 07:38:11PM +0530, Mukesh Ojha wrote:
>> Since, there is no guarantee that region.name will be 0-terminated
>> from the firmware side, replace kstrdup with kstrndup.
>>
>> Suggested-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
>> Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
> 
> Please don't send additional patches in-reply-to another patch, it makes
> it impossible to use b4 to pick up the first patch.
> 
> And please don't send two patches which clearly will conflict with
> each other. Now I had to manually apply the first patch...
> 

Really sorry, for the inconvenience.
will keep in mind.

Thanks,
-Mukesh

> Regards,
> Bjorn
> 
>> ---
>>   drivers/remoteproc/qcom_common.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/remoteproc/qcom_common.c b/drivers/remoteproc/qcom_common.c
>> index 020349f..7810f91 100644
>> --- a/drivers/remoteproc/qcom_common.c
>> +++ b/drivers/remoteproc/qcom_common.c
>> @@ -124,7 +124,7 @@ static int qcom_add_minidump_segments(struct rproc *rproc, struct minidump_subsy
>>   	for (i = 0; i < seg_cnt; i++) {
>>   		memcpy_fromio(&region, ptr + i, sizeof(region));
>>   		if (region.valid == MD_REGION_VALID) {
>> -			name = kstrdup(region.name, GFP_KERNEL);
>> +			name = kstrndup(region.name, MAX_REGION_NAME_LENGTH - 1, GFP_KERNEL);
>>   			if (!name) {
>>   				iounmap(ptr);
>>   				return -ENOMEM;
>> -- 
>> 2.7.4
>>
  

Patch

diff --git a/drivers/remoteproc/qcom_common.c b/drivers/remoteproc/qcom_common.c
index 020349f..7810f91 100644
--- a/drivers/remoteproc/qcom_common.c
+++ b/drivers/remoteproc/qcom_common.c
@@ -124,7 +124,7 @@  static int qcom_add_minidump_segments(struct rproc *rproc, struct minidump_subsy
 	for (i = 0; i < seg_cnt; i++) {
 		memcpy_fromio(&region, ptr + i, sizeof(region));
 		if (region.valid == MD_REGION_VALID) {
-			name = kstrdup(region.name, GFP_KERNEL);
+			name = kstrndup(region.name, MAX_REGION_NAME_LENGTH - 1, GFP_KERNEL);
 			if (!name) {
 				iounmap(ptr);
 				return -ENOMEM;