diff options
author | Ville Syrjälä <ville.syrjala@linux.intel.com> | 2012-04-05 14:35:18 -0400 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2012-04-20 07:38:20 -0400 |
commit | d1b45d5f0586041fe750d90a62ba09cffb3eace1 (patch) | |
tree | cd73534530031cce2d26bf1ba7e225b46539f813 /drivers/gpu/drm/drm_crtc.c | |
parent | 01b68b0483627631c738dcfca0dee7e22892c420 (diff) |
drm: Add sanity checks to framebuffer creation
Perform some basic sanity check on some of the parameters in
drm_mode_fb_cmd2.
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/drm_crtc.c')
-rw-r--r-- | drivers/gpu/drm/drm_crtc.c | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 1b79c953b4cc..4d4e8b055731 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c | |||
@@ -2185,6 +2185,47 @@ static int format_check(struct drm_mode_fb_cmd2 *r) | |||
2185 | } | 2185 | } |
2186 | } | 2186 | } |
2187 | 2187 | ||
2188 | static int framebuffer_check(struct drm_mode_fb_cmd2 *r) | ||
2189 | { | ||
2190 | int ret, hsub, vsub, num_planes, i; | ||
2191 | |||
2192 | ret = format_check(r); | ||
2193 | if (ret) { | ||
2194 | DRM_ERROR("bad framebuffer format 0x%08x\n", r->pixel_format); | ||
2195 | return ret; | ||
2196 | } | ||
2197 | |||
2198 | hsub = drm_format_horz_chroma_subsampling(r->pixel_format); | ||
2199 | vsub = drm_format_vert_chroma_subsampling(r->pixel_format); | ||
2200 | num_planes = drm_format_num_planes(r->pixel_format); | ||
2201 | |||
2202 | if (r->width == 0 || r->width % hsub) { | ||
2203 | DRM_ERROR("bad framebuffer width %u\n", r->height); | ||
2204 | return -EINVAL; | ||
2205 | } | ||
2206 | |||
2207 | if (r->height == 0 || r->height % vsub) { | ||
2208 | DRM_ERROR("bad framebuffer height %u\n", r->height); | ||
2209 | return -EINVAL; | ||
2210 | } | ||
2211 | |||
2212 | for (i = 0; i < num_planes; i++) { | ||
2213 | unsigned int width = r->width / (i != 0 ? hsub : 1); | ||
2214 | |||
2215 | if (!r->handles[i]) { | ||
2216 | DRM_ERROR("no buffer object handle for plane %d\n", i); | ||
2217 | return -EINVAL; | ||
2218 | } | ||
2219 | |||
2220 | if (r->pitches[i] < drm_format_plane_cpp(r->pixel_format, i) * width) { | ||
2221 | DRM_ERROR("bad pitch %u for plane %d\n", r->pitches[i], i); | ||
2222 | return -EINVAL; | ||
2223 | } | ||
2224 | } | ||
2225 | |||
2226 | return 0; | ||
2227 | } | ||
2228 | |||
2188 | /** | 2229 | /** |
2189 | * drm_mode_addfb2 - add an FB to the graphics configuration | 2230 | * drm_mode_addfb2 - add an FB to the graphics configuration |
2190 | * @inode: inode from the ioctl | 2231 | * @inode: inode from the ioctl |
@@ -2224,11 +2265,9 @@ int drm_mode_addfb2(struct drm_device *dev, | |||
2224 | return -EINVAL; | 2265 | return -EINVAL; |
2225 | } | 2266 | } |
2226 | 2267 | ||
2227 | ret = format_check(r); | 2268 | ret = framebuffer_check(r); |
2228 | if (ret) { | 2269 | if (ret) |
2229 | DRM_ERROR("bad framebuffer format 0x%08x\n", r->pixel_format); | ||
2230 | return ret; | 2270 | return ret; |
2231 | } | ||
2232 | 2271 | ||
2233 | mutex_lock(&dev->mode_config.mutex); | 2272 | mutex_lock(&dev->mode_config.mutex); |
2234 | 2273 | ||