Skip to content

Commit 279cc2e

Browse files
author
Thomas Zimmermann
committed
drm: Define DRM_FORMAT_MAX_PLANES
DRM uses a magic number of 4 for the maximum number of planes per color format. Declare this constant via DRM_FORMAT_MAX_PLANES and update the related code. Some code depends on the length of arrays that are now declared with DRM_FORMAT_MAX_PLANES. Convert it from '4' to ARRAY_SIZE. v2: * mention usage of ARRAY_SIZE() in the commit message (Maxime) * also fix error handling in drm_gem_fb_init_with_funcs() (kernel test robot) * include <drm/drm_fourcc.h> for DRM_FORMAT_MAX_PLANES Signed-off-by: Thomas Zimmermann <[email protected]> Reviewed-by: Sam Ravnborg <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 6e5b47a commit 279cc2e

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

drivers/gpu/drm/drm_gem_framebuffer_helper.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
4949
unsigned int plane)
5050
{
51-
if (plane >= 4)
51+
if (plane >= ARRAY_SIZE(fb->obj))
5252
return NULL;
5353

5454
return fb->obj[plane];
@@ -62,7 +62,8 @@ drm_gem_fb_init(struct drm_device *dev,
6262
struct drm_gem_object **obj, unsigned int num_planes,
6363
const struct drm_framebuffer_funcs *funcs)
6464
{
65-
int ret, i;
65+
unsigned int i;
66+
int ret;
6667

6768
drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
6869

@@ -86,9 +87,9 @@ drm_gem_fb_init(struct drm_device *dev,
8687
*/
8788
void drm_gem_fb_destroy(struct drm_framebuffer *fb)
8889
{
89-
int i;
90+
size_t i;
9091

91-
for (i = 0; i < 4; i++)
92+
for (i = 0; i < ARRAY_SIZE(fb->obj); i++)
9293
drm_gem_object_put(fb->obj[i]);
9394

9495
drm_framebuffer_cleanup(fb);
@@ -145,8 +146,9 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
145146
const struct drm_framebuffer_funcs *funcs)
146147
{
147148
const struct drm_format_info *info;
148-
struct drm_gem_object *objs[4];
149-
int ret, i;
149+
struct drm_gem_object *objs[DRM_FORMAT_MAX_PLANES];
150+
unsigned int i;
151+
int ret;
150152

151153
info = drm_get_format_info(dev, mode_cmd);
152154
if (!info) {
@@ -187,9 +189,10 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
187189
return 0;
188190

189191
err_gem_object_put:
190-
for (i--; i >= 0; i--)
192+
while (i > 0) {
193+
--i;
191194
drm_gem_object_put(objs[i]);
192-
195+
}
193196
return ret;
194197
}
195198
EXPORT_SYMBOL_GPL(drm_gem_fb_init_with_funcs);

include/drm/drm_fourcc.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
#include <linux/types.h>
2626
#include <uapi/drm/drm_fourcc.h>
2727

28+
/**
29+
* DRM_FORMAT_MAX_PLANES - maximum number of planes a DRM format can have
30+
*/
31+
#define DRM_FORMAT_MAX_PLANES 4u
32+
2833
/*
2934
* DRM formats are little endian. Define host endian variants for the
3035
* most common formats here, to reduce the #ifdefs needed in drivers.
@@ -78,7 +83,7 @@ struct drm_format_info {
7883
* triplet @char_per_block, @block_w, @block_h for better
7984
* describing the pixel format.
8085
*/
81-
u8 cpp[4];
86+
u8 cpp[DRM_FORMAT_MAX_PLANES];
8287

8388
/**
8489
* @char_per_block:
@@ -104,7 +109,7 @@ struct drm_format_info {
104109
* information from their drm_mode_config.get_format_info hook
105110
* if they want the core to be validating the pitch.
106111
*/
107-
u8 char_per_block[4];
112+
u8 char_per_block[DRM_FORMAT_MAX_PLANES];
108113
};
109114

110115
/**
@@ -113,15 +118,15 @@ struct drm_format_info {
113118
* Block width in pixels, this is intended to be accessed through
114119
* drm_format_info_block_width()
115120
*/
116-
u8 block_w[4];
121+
u8 block_w[DRM_FORMAT_MAX_PLANES];
117122

118123
/**
119124
* @block_h:
120125
*
121126
* Block height in pixels, this is intended to be accessed through
122127
* drm_format_info_block_height()
123128
*/
124-
u8 block_h[4];
129+
u8 block_h[DRM_FORMAT_MAX_PLANES];
125130

126131
/** @hsub: Horizontal chroma subsampling factor */
127132
u8 hsub;

include/drm/drm_framebuffer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
#include <linux/list.h>
2828
#include <linux/sched.h>
2929

30+
#include <drm/drm_fourcc.h>
3031
#include <drm/drm_mode_object.h>
3132

3233
struct drm_clip_rect;
3334
struct drm_device;
3435
struct drm_file;
35-
struct drm_format_info;
3636
struct drm_framebuffer;
3737
struct drm_gem_object;
3838

@@ -147,7 +147,7 @@ struct drm_framebuffer {
147147
* @pitches: Line stride per buffer. For userspace created object this
148148
* is copied from drm_mode_fb_cmd2.
149149
*/
150-
unsigned int pitches[4];
150+
unsigned int pitches[DRM_FORMAT_MAX_PLANES];
151151
/**
152152
* @offsets: Offset from buffer start to the actual pixel data in bytes,
153153
* per buffer. For userspace created object this is copied from
@@ -165,7 +165,7 @@ struct drm_framebuffer {
165165
* data (even for linear buffers). Specifying an x/y pixel offset is
166166
* instead done through the source rectangle in &struct drm_plane_state.
167167
*/
168-
unsigned int offsets[4];
168+
unsigned int offsets[DRM_FORMAT_MAX_PLANES];
169169
/**
170170
* @modifier: Data layout modifier. This is used to describe
171171
* tiling, or also special layouts (like compression) of auxiliary
@@ -210,7 +210,7 @@ struct drm_framebuffer {
210210
* This is used by the GEM framebuffer helpers, see e.g.
211211
* drm_gem_fb_create().
212212
*/
213-
struct drm_gem_object *obj[4];
213+
struct drm_gem_object *obj[DRM_FORMAT_MAX_PLANES];
214214
};
215215

216216
#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)

include/drm/drm_gem_atomic_helper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <linux/dma-buf-map.h>
77

8+
#include <drm/drm_fourcc.h>
89
#include <drm/drm_plane.h>
910

1011
struct drm_simple_display_pipe;
@@ -40,7 +41,7 @@ struct drm_shadow_plane_state {
4041
* The memory mappings stored in map should be established in the plane's
4142
* prepare_fb callback and removed in the cleanup_fb callback.
4243
*/
43-
struct dma_buf_map map[4];
44+
struct dma_buf_map map[DRM_FORMAT_MAX_PLANES];
4445
};
4546

4647
/**

0 commit comments

Comments
 (0)