# \[PATCH\]\[next\] fbcon: Use array3\_size() helper in scr\_memcpyw()

- Subsystems: FRAMEBUFFER CONSOLE, FRAMEBUFFER LAYER, FRAMEBUFFER CORE, THE REST
- Maintainers: Helge Deller, Thomas Zimmermann, Simona Vetter, Linus Torvalds
- Status: LANDED (fcf918b96662 · 2020-07-10 14:17)
- Landed in mainline as fcf918b96662 on 2020-07-10.
- List: linux-fbdev
- 2 messages, 2 authors
- Page: https://ratatoskr.run/linux-fbdev/2020/06/5999977/t

## \[PATCH\]\[next\] fbcon: Use array3\_size() helper in scr\_memcpyw()

- From: Gustavo A. R. Silva \<gustavoars@kernel.org\>
- Date: 2020-06-15 23:10:25 
- Message: https://ratatoskr.run/linux-fbdev/2020/06/5999977.md

```text
Use array3_size() helper instead of the open-coded version in scr_memcpyw()
and scr_memsetw(). These sorts of multiplication factors need to be wrapped
in array3_size().

This issue was found with the help of Coccinelle and, audited and fixed
manually.

Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/video/fbdev/core/fbcon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index 9d28a8e3328f..6af2734f2a7b 100644
--- a/drivers/video/fbdev/core/fbcon.c
+++ b/drivers/video/fbdev/core/fbcon.c
@@ -639,7 +639,7 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
 			       GFP_KERNEL);
 		if (save) {
 			int i = cols < new_cols ? cols : new_cols;
-			scr_memsetw(save, erase, logo_lines * new_cols * 2);
+			scr_memsetw(save, erase, array3_size(logo_lines, new_cols, 2));
 			r = q - step;
 			for (cnt = 0; cnt < logo_lines; cnt++, r += i)
 				scr_memcpyw(save + cnt * new_cols, r, 2 * i);
@@ -676,7 +676,7 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
 		q = (unsigned short *) (vc->vc_origin +
 					vc->vc_size_row *
 					rows);
-		scr_memcpyw(q, save, logo_lines * new_cols * 2);
+		scr_memcpyw(q, save, array3_size(logo_lines, new_cols, 2));
 		vc->vc_y += logo_lines;
 		vc->vc_pos += logo_lines * vc->vc_size_row;
 		kfree(save);
-- 
2.27.0
```

## Re: \[PATCH\]\[next\] fbcon: Use array3\_size() helper in scr\_memcpyw()

- From: Bartlomiej Zolnierkiewicz \<hidden\>
- Date: 2020-07-10 14:23:46 
- Message: https://ratatoskr.run/linux-fbdev/2020/07/6032036.md

```text

On 6/16/20 1:15 AM, Gustavo A. R. Silva wrote:
> Use array3_size() helper instead of the open-coded version in scr_memcpyw()
> and scr_memsetw(). These sorts of multiplication factors need to be wrapped
> in array3_size().
> 
> This issue was found with the help of Coccinelle and, audited and fixed
> manually.
> 
> Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Applied to drm-misc-next tree, thanks.

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics

> ---
>  drivers/video/fbdev/core/fbcon.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
> index 9d28a8e3328f..6af2734f2a7b 100644
> --- a/drivers/video/fbdev/core/fbcon.c
> +++ b/drivers/video/fbdev/core/fbcon.c
> @@ -639,7 +639,7 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
>  			       GFP_KERNEL);
>  		if (save) {
>  			int i = cols < new_cols ? cols : new_cols;
> -			scr_memsetw(save, erase, logo_lines * new_cols * 2);
> +			scr_memsetw(save, erase, array3_size(logo_lines, new_cols, 2));
>  			r = q - step;
>  			for (cnt = 0; cnt < logo_lines; cnt++, r += i)
>  				scr_memcpyw(save + cnt * new_cols, r, 2 * i);
> @@ -676,7 +676,7 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
>  		q = (unsigned short *) (vc->vc_origin +
>  					vc->vc_size_row *
>  					rows);
> -		scr_memcpyw(q, save, logo_lines * new_cols * 2);
> +		scr_memcpyw(q, save, array3_size(logo_lines, new_cols, 2));
>  		vc->vc_y += logo_lines;
>  		vc->vc_pos += logo_lines * vc->vc_size_row;
>  		kfree(save);
> 
```
