intel/isl: Add bounds-checking assertions in isl_format_get_layout

We add two assertions instead of one because the first assertion that
format != ISL_FORMAT_UNSUPPORTED is more descriptive and checks for a
real but unsupported enumerant while the second ensures that they don't
pass in garbage values.  We also update some other helpers to use
isl_format_get_layout instead of using the table directly so that they
get bounds checking too.

Cc: mesa-stable@lists.freedesktop.org
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
This commit is contained in:
Jason Ekstrand
2018-06-06 09:54:17 -07:00
parent c267f46ef2
commit 778e2881a0
2 changed files with 22 additions and 12 deletions

View File

@@ -389,6 +389,9 @@ enum isl_format {
ISL_FORMAT_GEN9_CCS_64BPP,
ISL_FORMAT_GEN9_CCS_128BPP,
/* An upper bound on the supported format enumerations */
ISL_NUM_FORMATS,
/* Hardware doesn't understand this out-of-band value */
ISL_FORMAT_UNSUPPORTED = UINT16_MAX,
};
@@ -1423,6 +1426,8 @@ isl_device_get_sample_counts(struct isl_device *dev);
static inline const struct isl_format_layout * ATTRIBUTE_CONST
isl_format_get_layout(enum isl_format fmt)
{
assert(fmt != ISL_FORMAT_UNSUPPORTED);
assert(fmt < ISL_NUM_FORMATS);
return &isl_format_layouts[fmt];
}
@@ -1431,7 +1436,7 @@ bool isl_format_is_valid(enum isl_format);
static inline const char * ATTRIBUTE_CONST
isl_format_get_name(enum isl_format fmt)
{
return isl_format_layouts[fmt].name;
return isl_format_get_layout(fmt)->name;
}
bool isl_format_supports_rendering(const struct gen_device_info *devinfo,
@@ -1546,7 +1551,7 @@ isl_format_block_is_1x1x1(enum isl_format fmt)
static inline bool
isl_format_is_srgb(enum isl_format fmt)
{
return isl_format_layouts[fmt].colorspace == ISL_COLORSPACE_SRGB;
return isl_format_get_layout(fmt)->colorspace == ISL_COLORSPACE_SRGB;
}
enum isl_format isl_format_srgb_to_linear(enum isl_format fmt);
@@ -1556,20 +1561,25 @@ isl_format_is_rgb(enum isl_format fmt)
{
if (isl_format_is_yuv(fmt))
return false;
return isl_format_layouts[fmt].channels.r.bits > 0 &&
isl_format_layouts[fmt].channels.g.bits > 0 &&
isl_format_layouts[fmt].channels.b.bits > 0 &&
isl_format_layouts[fmt].channels.a.bits == 0;
const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
return fmtl->channels.r.bits > 0 &&
fmtl->channels.g.bits > 0 &&
fmtl->channels.b.bits > 0 &&
fmtl->channels.a.bits == 0;
}
static inline bool
isl_format_is_rgbx(enum isl_format fmt)
{
return isl_format_layouts[fmt].channels.r.bits > 0 &&
isl_format_layouts[fmt].channels.g.bits > 0 &&
isl_format_layouts[fmt].channels.b.bits > 0 &&
isl_format_layouts[fmt].channels.a.bits > 0 &&
isl_format_layouts[fmt].channels.a.type == ISL_VOID;
const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
return fmtl->channels.r.bits > 0 &&
fmtl->channels.g.bits > 0 &&
fmtl->channels.b.bits > 0 &&
fmtl->channels.a.bits > 0 &&
fmtl->channels.a.type == ISL_VOID;
}
enum isl_format isl_format_rgb_to_rgba(enum isl_format rgb) ATTRIBUTE_CONST;

View File

@@ -316,6 +316,6 @@ isl_buffer_fill_image_param(const struct isl_device *dev,
{
*param = image_param_defaults;
param->stride[0] = isl_format_layouts[format].bpb / 8;
param->stride[0] = isl_format_get_layout(format)->bpb / 8;
param->size[0] = size / param->stride[0];
}