diff options
author | Michel Dänzer <michel@tungstengraphics.com> | 2007-05-25 14:37:08 -0400 |
---|---|---|
committer | Dave Airlie <airlied@linux.ie> | 2007-05-25 14:37:08 -0400 |
commit | c4814f9001a8dd28e39311a919beac34f778f76d (patch) | |
tree | 0ff5e1129973d7522964fef2659e11e29f31a270 /drivers | |
parent | 777c7738a598c6e8d4b850181a509757fb79cf36 (diff) |
drm: make sure the drawable code doesn't call malloc(0).
Signed-off-by: Michel Dänzer <michel@tungstengraphics.com>
Signed-off-by: Dave Airlie <airlied@linux.ie>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/char/drm/drm_drawable.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/drivers/char/drm/drm_drawable.c b/drivers/char/drm/drm_drawable.c index de37d5f74563..b33313be2547 100644 --- a/drivers/char/drm/drm_drawable.c +++ b/drivers/char/drm/drm_drawable.c | |||
@@ -172,38 +172,49 @@ int drm_rmdraw(DRM_IOCTL_ARGS) | |||
172 | 172 | ||
173 | bitfield_length = idx + 1; | 173 | bitfield_length = idx + 1; |
174 | 174 | ||
175 | if (idx != id / (8 * sizeof(*bitfield))) | 175 | bitfield = NULL; |
176 | bitfield = drm_alloc(bitfield_length * | ||
177 | sizeof(*bitfield), DRM_MEM_BUFS); | ||
178 | 176 | ||
179 | if (!bitfield && bitfield_length) { | 177 | if (bitfield_length) { |
180 | bitfield = dev->drw_bitfield; | 178 | if (bitfield_length != dev->drw_bitfield_length) |
181 | bitfield_length = dev->drw_bitfield_length; | 179 | bitfield = drm_alloc(bitfield_length * |
180 | sizeof(*bitfield), | ||
181 | DRM_MEM_BUFS); | ||
182 | |||
183 | if (!bitfield) { | ||
184 | bitfield = dev->drw_bitfield; | ||
185 | bitfield_length = dev->drw_bitfield_length; | ||
186 | } | ||
182 | } | 187 | } |
183 | } | 188 | } |
184 | 189 | ||
185 | if (bitfield != dev->drw_bitfield) { | 190 | if (bitfield != dev->drw_bitfield) { |
186 | info_length = 8 * sizeof(*bitfield) * bitfield_length; | 191 | info_length = 8 * sizeof(*bitfield) * bitfield_length; |
187 | 192 | ||
188 | info = drm_alloc(info_length * sizeof(*info), DRM_MEM_BUFS); | 193 | if (info_length) { |
194 | info = drm_alloc(info_length * sizeof(*info), | ||
195 | DRM_MEM_BUFS); | ||
189 | 196 | ||
190 | if (!info && info_length) { | 197 | if (!info) { |
191 | info = dev->drw_info; | 198 | info = dev->drw_info; |
192 | info_length = dev->drw_info_length; | 199 | info_length = dev->drw_info_length; |
193 | } | 200 | } |
201 | } else | ||
202 | info = NULL; | ||
194 | 203 | ||
195 | spin_lock_irqsave(&dev->drw_lock, irqflags); | 204 | spin_lock_irqsave(&dev->drw_lock, irqflags); |
196 | 205 | ||
197 | memcpy(bitfield, dev->drw_bitfield, bitfield_length * | 206 | if (bitfield) |
198 | sizeof(*bitfield)); | 207 | memcpy(bitfield, dev->drw_bitfield, bitfield_length * |
208 | sizeof(*bitfield)); | ||
199 | drm_free(dev->drw_bitfield, sizeof(*bitfield) * | 209 | drm_free(dev->drw_bitfield, sizeof(*bitfield) * |
200 | dev->drw_bitfield_length, DRM_MEM_BUFS); | 210 | dev->drw_bitfield_length, DRM_MEM_BUFS); |
201 | dev->drw_bitfield = bitfield; | 211 | dev->drw_bitfield = bitfield; |
202 | dev->drw_bitfield_length = bitfield_length; | 212 | dev->drw_bitfield_length = bitfield_length; |
203 | 213 | ||
204 | if (info != dev->drw_info) { | 214 | if (info != dev->drw_info) { |
205 | memcpy(info, dev->drw_info, info_length * | 215 | if (info) |
206 | sizeof(*info)); | 216 | memcpy(info, dev->drw_info, info_length * |
217 | sizeof(*info)); | ||
207 | drm_free(dev->drw_info, sizeof(*info) * | 218 | drm_free(dev->drw_info, sizeof(*info) * |
208 | dev->drw_info_length, DRM_MEM_BUFS); | 219 | dev->drw_info_length, DRM_MEM_BUFS); |
209 | dev->drw_info = info; | 220 | dev->drw_info = info; |