at master 866 B view raw
1// SPDX-License-Identifier: GPL-2.0-only 2 3#include <linux/export.h> 4#include <linux/limits.h> 5#include <linux/minmax.h> 6#include <linux/module.h> 7 8#include <drm/drm_print.h> 9 10#include "drm_sysfb_helper.h" 11 12int drm_sysfb_get_validated_int(struct drm_device *dev, const char *name, 13 u64 value, u32 max) 14{ 15 if (value > min(max, INT_MAX)) { 16 drm_warn(dev, "%s of %llu exceeds maximum of %u\n", name, value, max); 17 return -EINVAL; 18 } 19 return value; 20} 21EXPORT_SYMBOL(drm_sysfb_get_validated_int); 22 23int drm_sysfb_get_validated_int0(struct drm_device *dev, const char *name, 24 u64 value, u32 max) 25{ 26 if (!value) { 27 drm_warn(dev, "%s of 0 not allowed\n", name); 28 return -EINVAL; 29 } 30 return drm_sysfb_get_validated_int(dev, name, value, max); 31} 32EXPORT_SYMBOL(drm_sysfb_get_validated_int0); 33 34MODULE_DESCRIPTION("Helpers for DRM sysfb drivers"); 35MODULE_LICENSE("GPL");