warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
- User
warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
- Assistant
This warning suggests that you are performing arithmetic operations on a pointer of type
void *. In C, arithmetic operations onvoid *pointers are not allowed because the size of the pointed-to type is unknown.For example, consider the following code snippet:
void* ptr = malloc(10 * sizeof(int)); void* newPtr = ptr + 2;Here, the compiler will give a warning because you are adding an offset of 2 to
ptr, which is avoid *pointer. The compiler doesn't know the size of the data the pointer is pointing to, so it cannot correctly calculate the memory address resulting from the arithmetic.To resolve this warning, you need to cast the
void *pointer to the correct type before performing arithmetic operations.For example, in the code snippet above, you can cast the pointers to
int *before performing the arithmetic:void* ptr = malloc(10 * sizeof(int)); int* newPtr = (int*)ptr + 2; - User
how-to-get-physical-address-from-the-dmabuf-fd
- Assistant
To get the physical address from a
dmabuffile descriptor in Linux, you can use theioctlsystem call with theDMA_BUF_IOCTL_PHYScommand. Here's an example of how to do it:#include <stdio.h> #include <fcntl.h> #include <unistd.h> #include <sys/ioctl.h> #include <linux/dma-buf.h> int main() { int dmabuf_fd = open("/dev/dma-buf", O_RDWR); // Replace with the actual path to your dmabuf file unsigned long phys_addr; if (ioctl(dmabuf_fd, DMA_BUF_IOCTL_PHYS, &phys_addr) == -1) { perror("ioctl"); return 1; } printf("Physical Address: %lx\n", phys_addr); close(dmabuf_fd); return 0; }Make sure to replace
"/dev/dma-buf"with the path to yourdmabuffile. TheDMA_BUF_IOCTL_PHYScommand is used to retrieve the physical address from thedmabuffile descriptor, and it fills thephys_addrvariable with the result.Compile the code by running
gcc your_program.c -o your_program, and then execute the program. It should output the physical address of the file descriptor.