]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
drm/radeon/radeon_display: Decrease the size of allocated memory
authorErick Archer <erick.archer@outlook.com>
Sat, 30 Mar 2024 16:34:47 +0000 (17:34 +0100)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 10 Apr 2024 02:19:39 +0000 (22:19 -0400)
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
Link: https://github.com/KSPP/linux/issues/160
Acked-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Erick Archer <erick.archer@outlook.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/radeon/radeon.h
drivers/gpu/drm/radeon/radeon_display.c

index 3e5ff17e3cafb272dfc6326877470b26db43295a..0999c8eaae94adf1eea943d75624dfd94f33ece4 100644 (file)
@@ -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 */
index efd18c8d84c8330a810692ab98b6dfa935cfdb31..5f1d24d3120c4a438d6482e8186da748f60d34cd 100644 (file)
@@ -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