dde_linux: use correct type in lx_emul's `min`

* use a macro for `min` inside lx_emul/kernel.h
* unify the definition of the clamp function

Fix #2964
This commit is contained in:
Stefan Kalkowski 2018-09-05 12:45:21 +02:00 committed by Christian Helmuth
parent bc9f0fdc34
commit 1ec2f43713
13 changed files with 16 additions and 57 deletions

View File

@ -271,14 +271,6 @@ enum { SPRINTF_STR_LEN = 64 };
extern int panic_timeout; extern int panic_timeout;
extern struct atomic_notifier_head panic_notifier_list; extern struct atomic_notifier_head panic_notifier_list;
#define min(x, y) ({ \
typeof(x) _min1 = (x); \
typeof(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
/* linux/i2c.h */ /* linux/i2c.h */
#define __deprecated #define __deprecated

View File

@ -237,8 +237,6 @@ void vfree(void *addr);
struct pm_message {}; struct pm_message {};
typedef struct pm_message pm_message_t; typedef struct pm_message pm_message_t;
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
struct task_struct struct task_struct
{ {
char comm[16]; char comm[16];

View File

@ -596,7 +596,7 @@ int utf16s_to_utf8s(const wchar_t *pwcs, int len,
*/ */
u16 *out = (u16 *)s; u16 *out = (u16 *)s;
u16 *in = (u16 *)pwcs; u16 *in = (u16 *)pwcs;
int length = Genode::min(len, maxlen / 2); int length = min(len, maxlen / 2);
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
out[i] = in[i]; out[i] = in[i];

View File

@ -222,15 +222,6 @@ enum {
char *kasprintf(gfp_t gfp, const char *fmt, ...); char *kasprintf(gfp_t gfp, const char *fmt, ...);
int kstrtouint(const char *s, unsigned int base, unsigned int *res); int kstrtouint(const char *s, unsigned int base, unsigned int *res);
#define clamp(val, min, max) ({ \
typeof(val) __val = (val); \
typeof(min) __min = (min); \
typeof(max) __max = (max); \
(void) (&__val == &__min); \
(void) (&__val == &__max); \
__val = __val < __min ? __min: __val; \
__val > __max ? __max: __val; })
#define rounddown(x, y) ( \ #define rounddown(x, y) ( \
{ \ { \
typeof(x) __x = (x); \ typeof(x) __x = (x); \

View File

@ -193,8 +193,6 @@ struct __una_u32 { u32 x; } __attribute__((packed));
u16 get_unaligned_le16(const void *p); u16 get_unaligned_le16(const void *p);
u32 get_unaligned_le32(const void *p); u32 get_unaligned_le32(const void *p);
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
struct completion struct completion
{ {
unsigned int done; unsigned int done;

View File

@ -98,19 +98,6 @@ static inline void panic(const char *fmt, ...)
type __max2 = (y); \ type __max2 = (y); \
__max1 > __max2 ? __max1: __max2; }) __max1 > __max2 ? __max1: __max2; })
/**
* Return minimum of two given values
*
* XXX check how this function is used (argument types)
*/
static inline size_t min(size_t a, size_t b) {
return a < b ? a : b; }
/**
* Return maximum of two given values
*
* XXX check how this function is used (argument types)
*/
#define max(x, y) ({ \ #define max(x, y) ({ \
typeof(x) _max1 = (x); \ typeof(x) _max1 = (x); \
typeof(y) _max2 = (y); \ typeof(y) _max2 = (y); \
@ -121,6 +108,11 @@ static inline size_t min(size_t a, size_t b) {
type __min2 = (y); \ type __min2 = (y); \
__min1 < __min2 ? __min1: __min2; }) __min1 < __min2 ? __min1: __min2; })
#define min(x, y) ({ \
typeof(x) _min1 = (x); \
typeof(y) _min2 = (y); \
_min1 > _min2 ? _min2 : _min1; })
#define abs(x) ( { \ #define abs(x) ( { \
typeof (x) _x = (x); \ typeof (x) _x = (x); \
_x < 0 ? -_x : _x; }) _x < 0 ? -_x : _x; })
@ -138,6 +130,8 @@ static inline size_t min(size_t a, size_t b) {
#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
#define round_down(x, y) ((x) & ~__round_mask(x, y)) #define round_down(x, y) ((x) & ~__round_mask(x, y))
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
#define clamp_val(val, min, max) ({ \ #define clamp_val(val, min, max) ({ \
typeof(val) __val = (val); \ typeof(val) __val = (val); \
typeof(val) __min = (min); \ typeof(val) __min = (min); \

View File

@ -208,7 +208,6 @@ DUMMY(-1, cancel_delayed_work_sync)
DUMMY(-1, capable) DUMMY(-1, capable)
DUMMY(-1, cipso_v4_validate) DUMMY(-1, cipso_v4_validate)
DUMMY(-1, __clear_bit) DUMMY(-1, __clear_bit)
DUMMY(-1, clamp)
DUMMY(-1, clear_bit) DUMMY(-1, clear_bit)
DUMMY(-1, cond_resched) DUMMY(-1, cond_resched)
DUMMY(-1, cond_resched_softirq) DUMMY(-1, cond_resched_softirq)
@ -330,7 +329,6 @@ DUMMY(-1, linkwatch_init_dev)
DUMMY(-1, linkwatch_run_queue) DUMMY(-1, linkwatch_run_queue)
DUMMY(-1, local_softirq_pending) DUMMY(-1, local_softirq_pending)
DUMMY(-1, lockdep_rtnl_is_held) DUMMY(-1, lockdep_rtnl_is_held)
DUMMY(-1, min)
DUMMY(-1, module_put) DUMMY(-1, module_put)
DUMMY(-1, move_addr_to_kernel) DUMMY(-1, move_addr_to_kernel)
DUMMY(-1, mq_qdisc_ops) DUMMY(-1, mq_qdisc_ops)

View File

@ -311,8 +311,6 @@ int scnprintf(char *, size_t, const char *, ...);
buf; \ buf; \
}) })
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
char *get_options(const char *str, int nints, int *ints); char *get_options(const char *str, int nints, int *ints);
int hex_to_bin(char); int hex_to_bin(char);

View File

@ -239,7 +239,7 @@ class Net::Socketcall : public Lxip::Socketcall,
(struct Linux::sockaddr *)&_call.addr, (struct Linux::sockaddr *)&_call.addr,
&len, peer); &len, peer);
*_call.accept.len = Linux::min(*_call.accept.len, len); *_call.accept.len = min(*_call.accept.len, len);
Genode::memcpy(_call.accept.addr, &_call.addr, *_call.accept.len); Genode::memcpy(_call.accept.addr, &_call.addr, *_call.accept.len);
} }

View File

@ -267,15 +267,6 @@ int kstrtouint(const char *s, unsigned int base, unsigned int *res);
int kstrtoul(const char *s, unsigned int base, unsigned long *res); int kstrtoul(const char *s, unsigned int base, unsigned long *res);
int kstrtou8(const char *s, unsigned int base, u8 *res); int kstrtou8(const char *s, unsigned int base, u8 *res);
#define clamp(val, min, max) ({ \
typeof(val) __val = (val); \
typeof(min) __min = (min); \
typeof(max) __max = (max); \
(void) (&__val == &__min); \
(void) (&__val == &__max); \
__val = __val < __min ? __min: __val; \
__val > __max ? __max: __val; })
#define rounddown(x, y) ( \ #define rounddown(x, y) ( \
{ \ { \
typeof(x) __x = (x); \ typeof(x) __x = (x); \

View File

@ -18,6 +18,12 @@
#include <nic/component.h> #include <nic/component.h>
#include <root/component.h> #include <root/component.h>
#include <lx_emul.h>
#include <lx_emul/extern_c_begin.h>
#include <linux/usb.h>
#include <linux/usb/usbnet.h>
#include <lx_emul/extern_c_end.h>
namespace Usb_nic { namespace Usb_nic {
using namespace Genode; using namespace Genode;
using Genode::size_t; using Genode::size_t;

View File

@ -899,7 +899,7 @@ int utf16s_to_utf8s(const wchar_t *pwcs, int len,
*/ */
u16 *out = (u16 *)s; u16 *out = (u16 *)s;
u16 *in = (u16 *)pwcs; u16 *in = (u16 *)pwcs;
int length = Genode::min(len, maxlen / 2); int length = min(len, maxlen / 2);
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
out[i] = in[i]; out[i] = in[i];

View File

@ -17,19 +17,12 @@
#include <nic/xml_node.h> #include <nic/xml_node.h>
#include <util/xml_node.h> #include <util/xml_node.h>
#include <lx_emul.h>
#include <lx_emul/extern_c_begin.h>
#include <linux/usb.h>
#include <linux/usb/usbnet.h>
#include <lx_emul/extern_c_end.h>
#include <lx_kit/env.h> #include <lx_kit/env.h>
#include <lx_kit/malloc.h> #include <lx_kit/malloc.h>
#include <usb_nic_component.h> #include <usb_nic_component.h>
#include "signal.h" #include "signal.h"
static Signal_helper *_signal = 0; static Signal_helper *_signal = 0;
enum { enum {