* [PATCH v2] drm/radeon/radeon_display: Decrease the size of allocated memory
@ 2024-03-30 16:34 Erick Archer
2024-04-01 12:35 ` Christian König
0 siblings, 1 reply; 3+ messages in thread
From: Erick Archer @ 2024-03-30 16:34 UTC (permalink / raw)
To: Alex Deucher, Christian König, Pan, Xinhui, David Airlie,
Daniel Vetter, Gustavo A. R. Silva, Kees Cook
Cc: Erick Archer, amd-gfx, dri-devel, linux-kernel, linux-hardening
This is an effort to get rid of all multiplications from allocation
functions in order to prevent integer overflows [1] [2].
In this case, the memory allocated to store RADEONFB_CONN_LIMIT pointers
to "drm_connector" structures can be avoided. This is because this
memory area is never accessed.
Also, in the kzalloc function, it is preferred to use sizeof(*pointer)
instead of sizeof(type) due to the type of the variable can change and
one needs not change the former (unlike the latter).
At the same time take advantage to remove the "#if 0" block, the code
where the removed memory area was accessed, and the RADEONFB_CONN_LIMIT
constant due to now is never used.
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1]
Link: https://github.com/KSPP/linux/issues/160 [2]
Signed-off-by: Erick Archer <erick.archer@outlook.com>
---
Changes in v2:
- Rebase against linux-next.
Previous versions:
v1 -> https://lore.kernel.org/linux-hardening/20240222180431.7451-1-erick.archer@gmx.com/
Hi everyone,
Any comments would be greatly appreciated. The first version was
not commented.
Thanks,
Erick
---
drivers/gpu/drm/radeon/radeon.h | 1 -
drivers/gpu/drm/radeon/radeon_display.c | 8 +-------
2 files changed, 1 insertion(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 3e5ff17e3caf..0999c8eaae94 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -132,7 +132,6 @@ extern int radeon_cik_support;
/* RADEON_IB_POOL_SIZE must be a power of 2 */
#define RADEON_IB_POOL_SIZE 16
#define RADEON_DEBUGFS_MAX_COMPONENTS 32
-#define RADEONFB_CONN_LIMIT 4
#define RADEON_BIOS_NUM_SCRATCH 8
/* internal ring indices */
diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
index efd18c8d84c8..5f1d24d3120c 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -683,7 +683,7 @@ static void radeon_crtc_init(struct drm_device *dev, int index)
struct radeon_device *rdev = dev->dev_private;
struct radeon_crtc *radeon_crtc;
- radeon_crtc = kzalloc(sizeof(struct radeon_crtc) + (RADEONFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
+ radeon_crtc = kzalloc(sizeof(*radeon_crtc), GFP_KERNEL);
if (radeon_crtc == NULL)
return;
@@ -709,12 +709,6 @@ static void radeon_crtc_init(struct drm_device *dev, int index)
dev->mode_config.cursor_width = radeon_crtc->max_cursor_width;
dev->mode_config.cursor_height = radeon_crtc->max_cursor_height;
-#if 0
- radeon_crtc->mode_set.crtc = &radeon_crtc->base;
- radeon_crtc->mode_set.connectors = (struct drm_connector **)(radeon_crtc + 1);
- radeon_crtc->mode_set.num_connectors = 0;
-#endif
-
if (rdev->is_atom_bios && (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom))
radeon_atombios_init_crtc(dev, radeon_crtc);
else
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] drm/radeon/radeon_display: Decrease the size of allocated memory
2024-03-30 16:34 [PATCH v2] drm/radeon/radeon_display: Decrease the size of allocated memory Erick Archer
@ 2024-04-01 12:35 ` Christian König
2024-04-08 20:05 ` Alex Deucher
0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2024-04-01 12:35 UTC (permalink / raw)
To: Erick Archer, Alex Deucher, Pan, Xinhui, David Airlie,
Daniel Vetter, Gustavo A. R. Silva, Kees Cook
Cc: amd-gfx, dri-devel, linux-kernel, linux-hardening
Am 30.03.24 um 17:34 schrieb Erick Archer:
> This is an effort to get rid of all multiplications from allocation
> functions in order to prevent integer overflows [1] [2].
>
> In this case, the memory allocated to store RADEONFB_CONN_LIMIT pointers
> to "drm_connector" structures can be avoided. This is because this
> memory area is never accessed.
>
> Also, in the kzalloc function, it is preferred to use sizeof(*pointer)
> instead of sizeof(type) due to the type of the variable can change and
> one needs not change the former (unlike the latter).
>
> At the same time take advantage to remove the "#if 0" block, the code
> where the removed memory area was accessed, and the RADEONFB_CONN_LIMIT
> constant due to now is never used.
>
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1]
> Link: https://github.com/KSPP/linux/issues/160 [2]
> Signed-off-by: Erick Archer <erick.archer@outlook.com>
Well in general we don't do any new feature development any more for the
radeon driver.
But this cleanup looks so straight forward that the risk of breaking
something is probably very low.
Acked-by from my side, but Alex should probably take a look as well.
Regards,
Christian.
> ---
> Changes in v2:
> - Rebase against linux-next.
>
> Previous versions:
> v1 -> https://lore.kernel.org/linux-hardening/20240222180431.7451-1-erick.archer@gmx.com/
>
> Hi everyone,
>
> Any comments would be greatly appreciated. The first version was
> not commented.
>
> Thanks,
> Erick
> ---
> drivers/gpu/drm/radeon/radeon.h | 1 -
> drivers/gpu/drm/radeon/radeon_display.c | 8 +-------
> 2 files changed, 1 insertion(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
> index 3e5ff17e3caf..0999c8eaae94 100644
> --- a/drivers/gpu/drm/radeon/radeon.h
> +++ b/drivers/gpu/drm/radeon/radeon.h
> @@ -132,7 +132,6 @@ extern int radeon_cik_support;
> /* RADEON_IB_POOL_SIZE must be a power of 2 */
> #define RADEON_IB_POOL_SIZE 16
> #define RADEON_DEBUGFS_MAX_COMPONENTS 32
> -#define RADEONFB_CONN_LIMIT 4
> #define RADEON_BIOS_NUM_SCRATCH 8
>
> /* internal ring indices */
> diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
> index efd18c8d84c8..5f1d24d3120c 100644
> --- a/drivers/gpu/drm/radeon/radeon_display.c
> +++ b/drivers/gpu/drm/radeon/radeon_display.c
> @@ -683,7 +683,7 @@ static void radeon_crtc_init(struct drm_device *dev, int index)
> struct radeon_device *rdev = dev->dev_private;
> struct radeon_crtc *radeon_crtc;
>
> - radeon_crtc = kzalloc(sizeof(struct radeon_crtc) + (RADEONFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
> + radeon_crtc = kzalloc(sizeof(*radeon_crtc), GFP_KERNEL);
> if (radeon_crtc == NULL)
> return;
>
> @@ -709,12 +709,6 @@ static void radeon_crtc_init(struct drm_device *dev, int index)
> dev->mode_config.cursor_width = radeon_crtc->max_cursor_width;
> dev->mode_config.cursor_height = radeon_crtc->max_cursor_height;
>
> -#if 0
> - radeon_crtc->mode_set.crtc = &radeon_crtc->base;
> - radeon_crtc->mode_set.connectors = (struct drm_connector **)(radeon_crtc + 1);
> - radeon_crtc->mode_set.num_connectors = 0;
> -#endif
> -
> if (rdev->is_atom_bios && (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom))
> radeon_atombios_init_crtc(dev, radeon_crtc);
> else
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] drm/radeon/radeon_display: Decrease the size of allocated memory
2024-04-01 12:35 ` Christian König
@ 2024-04-08 20:05 ` Alex Deucher
0 siblings, 0 replies; 3+ messages in thread
From: Alex Deucher @ 2024-04-08 20:05 UTC (permalink / raw)
To: Christian König
Cc: Erick Archer, Alex Deucher, Pan, Xinhui, David Airlie,
Daniel Vetter, Gustavo A. R. Silva, Kees Cook, amd-gfx,
dri-devel, linux-kernel, linux-hardening
On Mon, Apr 1, 2024 at 8:35 AM Christian König <christian.koenig@amd.com> wrote:
>
> Am 30.03.24 um 17:34 schrieb Erick Archer:
> > This is an effort to get rid of all multiplications from allocation
> > functions in order to prevent integer overflows [1] [2].
> >
> > In this case, the memory allocated to store RADEONFB_CONN_LIMIT pointers
> > to "drm_connector" structures can be avoided. This is because this
> > memory area is never accessed.
> >
> > Also, in the kzalloc function, it is preferred to use sizeof(*pointer)
> > instead of sizeof(type) due to the type of the variable can change and
> > one needs not change the former (unlike the latter).
> >
> > At the same time take advantage to remove the "#if 0" block, the code
> > where the removed memory area was accessed, and the RADEONFB_CONN_LIMIT
> > constant due to now is never used.
> >
> > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1]
> > Link: https://github.com/KSPP/linux/issues/160 [2]
> > Signed-off-by: Erick Archer <erick.archer@outlook.com>
>
> Well in general we don't do any new feature development any more for the
> radeon driver.
>
> But this cleanup looks so straight forward that the risk of breaking
> something is probably very low.
>
> Acked-by from my side, but Alex should probably take a look as well.
I can't remember why that was done that way. Maybe some leftover from
the early KMS days before we finalized the fbdev interactions?
Anyway, patch applied. Thanks.
Alex
>
> Regards,
> Christian.
>
> > ---
> > Changes in v2:
> > - Rebase against linux-next.
> >
> > Previous versions:
> > v1 -> https://lore.kernel.org/linux-hardening/20240222180431.7451-1-erick.archer@gmx.com/
> >
> > Hi everyone,
> >
> > Any comments would be greatly appreciated. The first version was
> > not commented.
> >
> > Thanks,
> > Erick
> > ---
> > drivers/gpu/drm/radeon/radeon.h | 1 -
> > drivers/gpu/drm/radeon/radeon_display.c | 8 +-------
> > 2 files changed, 1 insertion(+), 8 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
> > index 3e5ff17e3caf..0999c8eaae94 100644
> > --- a/drivers/gpu/drm/radeon/radeon.h
> > +++ b/drivers/gpu/drm/radeon/radeon.h
> > @@ -132,7 +132,6 @@ extern int radeon_cik_support;
> > /* RADEON_IB_POOL_SIZE must be a power of 2 */
> > #define RADEON_IB_POOL_SIZE 16
> > #define RADEON_DEBUGFS_MAX_COMPONENTS 32
> > -#define RADEONFB_CONN_LIMIT 4
> > #define RADEON_BIOS_NUM_SCRATCH 8
> >
> > /* internal ring indices */
> > diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
> > index efd18c8d84c8..5f1d24d3120c 100644
> > --- a/drivers/gpu/drm/radeon/radeon_display.c
> > +++ b/drivers/gpu/drm/radeon/radeon_display.c
> > @@ -683,7 +683,7 @@ static void radeon_crtc_init(struct drm_device *dev, int index)
> > struct radeon_device *rdev = dev->dev_private;
> > struct radeon_crtc *radeon_crtc;
> >
> > - radeon_crtc = kzalloc(sizeof(struct radeon_crtc) + (RADEONFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
> > + radeon_crtc = kzalloc(sizeof(*radeon_crtc), GFP_KERNEL);
> > if (radeon_crtc == NULL)
> > return;
> >
> > @@ -709,12 +709,6 @@ static void radeon_crtc_init(struct drm_device *dev, int index)
> > dev->mode_config.cursor_width = radeon_crtc->max_cursor_width;
> > dev->mode_config.cursor_height = radeon_crtc->max_cursor_height;
> >
> > -#if 0
> > - radeon_crtc->mode_set.crtc = &radeon_crtc->base;
> > - radeon_crtc->mode_set.connectors = (struct drm_connector **)(radeon_crtc + 1);
> > - radeon_crtc->mode_set.num_connectors = 0;
> > -#endif
> > -
> > if (rdev->is_atom_bios && (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom))
> > radeon_atombios_init_crtc(dev, radeon_crtc);
> > else
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-08 20:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-30 16:34 [PATCH v2] drm/radeon/radeon_display: Decrease the size of allocated memory Erick Archer
2024-04-01 12:35 ` Christian König
2024-04-08 20:05 ` Alex Deucher
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®