Re: [PATCH v4 06/20] kernel-shark: Add basic methods for Data streams

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 18 Nov 2020 16:49:49 +0200
"Yordan Karadzhov (VMware)" <y.karadz@xxxxxxxxx> wrote:

> +/**
> + * Bit mask (16-63) used when converting indexes to pointers and vise-versa.
> + */
> +#define INVALID_STREAM_MASK	(~((uint64_t) INDEX_MASK))

This wont work on a 32 bit machine, as pointers are 32 bits not 64.

> +
> +static int index_from_ptr(void *ptr)
> +{
> +	unsigned long index = (unsigned long) ptr;
> +
> +	return (int) (index & INDEX_MASK);
> +}
> +
> +static void *index_to_ptr(unsigned int index)
> +{
> +	unsigned long p;
> +
> +	p = INVALID_STREAM_MASK | index;
> +
> +	return (void *) p;
> +}
> +
> +static bool kshark_is_valid_stream(void *ptr)
> +{
> +	unsigned long p = (unsigned long) ptr;
> +	bool v = !((p & ~INDEX_MASK) == INVALID_STREAM_MASK);

On 32 bit, the above will always fail, because unsigned long is 32
bits (as is void *), but INVALID_STREAM_MASK is 64 bits. And the two
could never equal each other.

-- Steve


> +
> +	return p && v;
> +}
> +



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux