forked from mirrors/linux
drm/sysfb: Share helpers for integer validation
Provide sysfb helpers for validating framebuffer integer values against limits. Update drivers. If a driver did not specify a limit for a certain value, use INT_MAX. v2: - declare module information near EOF (Javier) Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com> Link: https://lore.kernel.org/r/20250410083834.10810-3-tzimmermann@suse.de
This commit is contained in:
parent
314c45e39e
commit
6046b49baf
6 changed files with 48 additions and 72 deletions
|
|
@ -1,8 +1,35 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-only
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
|
||||||
|
#include <linux/export.h>
|
||||||
|
#include <linux/limits.h>
|
||||||
|
#include <linux/minmax.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
|
|
||||||
|
#include <drm/drm_print.h>
|
||||||
|
|
||||||
#include "drm_sysfb_helper.h"
|
#include "drm_sysfb_helper.h"
|
||||||
|
|
||||||
|
int drm_sysfb_get_validated_int(struct drm_device *dev, const char *name,
|
||||||
|
u64 value, u32 max)
|
||||||
|
{
|
||||||
|
if (value > min(max, INT_MAX)) {
|
||||||
|
drm_warn(dev, "%s of %llu exceeds maximum of %u\n", name, value, max);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(drm_sysfb_get_validated_int);
|
||||||
|
|
||||||
|
int drm_sysfb_get_validated_int0(struct drm_device *dev, const char *name,
|
||||||
|
u64 value, u32 max)
|
||||||
|
{
|
||||||
|
if (!value) {
|
||||||
|
drm_warn(dev, "%s of 0 not allowed\n", name);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
return drm_sysfb_get_validated_int(dev, name, value, max);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(drm_sysfb_get_validated_int0);
|
||||||
|
|
||||||
MODULE_DESCRIPTION("Helpers for DRM sysfb drivers");
|
MODULE_DESCRIPTION("Helpers for DRM sysfb drivers");
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,15 @@
|
||||||
struct drm_format_info;
|
struct drm_format_info;
|
||||||
struct drm_scanout_buffer;
|
struct drm_scanout_buffer;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Input parsing
|
||||||
|
*/
|
||||||
|
|
||||||
|
int drm_sysfb_get_validated_int(struct drm_device *dev, const char *name,
|
||||||
|
u64 value, u32 max);
|
||||||
|
int drm_sysfb_get_validated_int0(struct drm_device *dev, const char *name,
|
||||||
|
u64 value, u32 max);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display modes
|
* Display modes
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -33,28 +33,6 @@
|
||||||
#define DRIVER_MAJOR 1
|
#define DRIVER_MAJOR 1
|
||||||
#define DRIVER_MINOR 0
|
#define DRIVER_MINOR 0
|
||||||
|
|
||||||
static int efidrm_get_validated_int(struct drm_device *dev, const char *name,
|
|
||||||
u64 value, u32 max)
|
|
||||||
{
|
|
||||||
if (max > INT_MAX)
|
|
||||||
max = INT_MAX;
|
|
||||||
if (value > max) {
|
|
||||||
drm_err(dev, "%s of %llu exceeds maximum of %u\n", name, value, max);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int efidrm_get_validated_int0(struct drm_device *dev, const char *name,
|
|
||||||
u64 value, u32 max)
|
|
||||||
{
|
|
||||||
if (!value) {
|
|
||||||
drm_err(dev, "%s of 0 not allowed\n", name);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
return efidrm_get_validated_int(dev, name, value, max);
|
|
||||||
}
|
|
||||||
|
|
||||||
static s64 efidrm_get_validated_size0(struct drm_device *dev, const char *name,
|
static s64 efidrm_get_validated_size0(struct drm_device *dev, const char *name,
|
||||||
u64 value, u64 max)
|
u64 value, u64 max)
|
||||||
{
|
{
|
||||||
|
|
@ -70,12 +48,12 @@ static s64 efidrm_get_validated_size0(struct drm_device *dev, const char *name,
|
||||||
|
|
||||||
static int efidrm_get_width_si(struct drm_device *dev, const struct screen_info *si)
|
static int efidrm_get_width_si(struct drm_device *dev, const struct screen_info *si)
|
||||||
{
|
{
|
||||||
return efidrm_get_validated_int0(dev, "width", si->lfb_width, U16_MAX);
|
return drm_sysfb_get_validated_int0(dev, "width", si->lfb_width, U16_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int efidrm_get_height_si(struct drm_device *dev, const struct screen_info *si)
|
static int efidrm_get_height_si(struct drm_device *dev, const struct screen_info *si)
|
||||||
{
|
{
|
||||||
return efidrm_get_validated_int0(dev, "height", si->lfb_height, U16_MAX);
|
return drm_sysfb_get_validated_int0(dev, "height", si->lfb_height, U16_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct resource *efidrm_get_memory_si(struct drm_device *dev,
|
static struct resource *efidrm_get_memory_si(struct drm_device *dev,
|
||||||
|
|
@ -102,7 +80,8 @@ static int efidrm_get_stride_si(struct drm_device *dev, const struct screen_info
|
||||||
if (!lfb_linelength)
|
if (!lfb_linelength)
|
||||||
lfb_linelength = drm_format_info_min_pitch(format, 0, width);
|
lfb_linelength = drm_format_info_min_pitch(format, 0, width);
|
||||||
|
|
||||||
return efidrm_get_validated_int0(dev, "stride", lfb_linelength, div64_u64(size, height));
|
return drm_sysfb_get_validated_int0(dev, "stride", lfb_linelength,
|
||||||
|
div64_u64(size, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
static u64 efidrm_get_visible_size_si(struct drm_device *dev, const struct screen_info *si,
|
static u64 efidrm_get_visible_size_si(struct drm_device *dev, const struct screen_info *si,
|
||||||
|
|
|
||||||
|
|
@ -78,20 +78,12 @@ enum ofdrm_model {
|
||||||
|
|
||||||
static int display_get_validated_int(struct drm_device *dev, const char *name, uint32_t value)
|
static int display_get_validated_int(struct drm_device *dev, const char *name, uint32_t value)
|
||||||
{
|
{
|
||||||
if (value > INT_MAX) {
|
return drm_sysfb_get_validated_int(dev, name, value, INT_MAX);
|
||||||
drm_err(dev, "invalid framebuffer %s of %u\n", name, value);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
return (int)value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int display_get_validated_int0(struct drm_device *dev, const char *name, uint32_t value)
|
static int display_get_validated_int0(struct drm_device *dev, const char *name, uint32_t value)
|
||||||
{
|
{
|
||||||
if (!value) {
|
return drm_sysfb_get_validated_int0(dev, name, value, INT_MAX);
|
||||||
drm_err(dev, "invalid framebuffer %s of %u\n", name, value);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
return display_get_validated_int(dev, name, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct drm_format_info *display_get_validated_format(struct drm_device *dev,
|
static const struct drm_format_info *display_get_validated_format(struct drm_device *dev,
|
||||||
|
|
|
||||||
|
|
@ -42,24 +42,14 @@ static int
|
||||||
simplefb_get_validated_int(struct drm_device *dev, const char *name,
|
simplefb_get_validated_int(struct drm_device *dev, const char *name,
|
||||||
uint32_t value)
|
uint32_t value)
|
||||||
{
|
{
|
||||||
if (value > INT_MAX) {
|
return drm_sysfb_get_validated_int(dev, name, value, INT_MAX);
|
||||||
drm_err(dev, "simplefb: invalid framebuffer %s of %u\n",
|
|
||||||
name, value);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
return (int)value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
simplefb_get_validated_int0(struct drm_device *dev, const char *name,
|
simplefb_get_validated_int0(struct drm_device *dev, const char *name,
|
||||||
uint32_t value)
|
uint32_t value)
|
||||||
{
|
{
|
||||||
if (!value) {
|
return drm_sysfb_get_validated_int0(dev, name, value, INT_MAX);
|
||||||
drm_err(dev, "simplefb: invalid framebuffer %s of %u\n",
|
|
||||||
name, value);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
return simplefb_get_validated_int(dev, name, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct drm_format_info *
|
static const struct drm_format_info *
|
||||||
|
|
|
||||||
|
|
@ -36,28 +36,6 @@
|
||||||
|
|
||||||
#define VESADRM_GAMMA_LUT_SIZE 256
|
#define VESADRM_GAMMA_LUT_SIZE 256
|
||||||
|
|
||||||
static int vesadrm_get_validated_int(struct drm_device *dev, const char *name,
|
|
||||||
u64 value, u32 max)
|
|
||||||
{
|
|
||||||
if (max > INT_MAX)
|
|
||||||
max = INT_MAX;
|
|
||||||
if (value > max) {
|
|
||||||
drm_err(dev, "%s of %llu exceeds maximum of %u\n", name, value, max);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int vesadrm_get_validated_int0(struct drm_device *dev, const char *name,
|
|
||||||
u64 value, u32 max)
|
|
||||||
{
|
|
||||||
if (!value) {
|
|
||||||
drm_err(dev, "%s of 0 not allowed\n", name);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
return vesadrm_get_validated_int(dev, name, value, max);
|
|
||||||
}
|
|
||||||
|
|
||||||
static s64 vesadrm_get_validated_size0(struct drm_device *dev, const char *name,
|
static s64 vesadrm_get_validated_size0(struct drm_device *dev, const char *name,
|
||||||
u64 value, u64 max)
|
u64 value, u64 max)
|
||||||
{
|
{
|
||||||
|
|
@ -73,12 +51,12 @@ static s64 vesadrm_get_validated_size0(struct drm_device *dev, const char *name,
|
||||||
|
|
||||||
static int vesadrm_get_width_si(struct drm_device *dev, const struct screen_info *si)
|
static int vesadrm_get_width_si(struct drm_device *dev, const struct screen_info *si)
|
||||||
{
|
{
|
||||||
return vesadrm_get_validated_int0(dev, "width", si->lfb_width, U16_MAX);
|
return drm_sysfb_get_validated_int0(dev, "width", si->lfb_width, U16_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vesadrm_get_height_si(struct drm_device *dev, const struct screen_info *si)
|
static int vesadrm_get_height_si(struct drm_device *dev, const struct screen_info *si)
|
||||||
{
|
{
|
||||||
return vesadrm_get_validated_int0(dev, "height", si->lfb_height, U16_MAX);
|
return drm_sysfb_get_validated_int0(dev, "height", si->lfb_height, U16_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct resource *vesadrm_get_memory_si(struct drm_device *dev,
|
static struct resource *vesadrm_get_memory_si(struct drm_device *dev,
|
||||||
|
|
@ -105,7 +83,8 @@ static int vesadrm_get_stride_si(struct drm_device *dev, const struct screen_inf
|
||||||
if (!lfb_linelength)
|
if (!lfb_linelength)
|
||||||
lfb_linelength = drm_format_info_min_pitch(format, 0, width);
|
lfb_linelength = drm_format_info_min_pitch(format, 0, width);
|
||||||
|
|
||||||
return vesadrm_get_validated_int0(dev, "stride", lfb_linelength, div64_u64(size, height));
|
return drm_sysfb_get_validated_int0(dev, "stride", lfb_linelength,
|
||||||
|
div64_u64(size, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
static u64 vesadrm_get_visible_size_si(struct drm_device *dev, const struct screen_info *si,
|
static u64 vesadrm_get_visible_size_si(struct drm_device *dev, const struct screen_info *si,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue