bpf, events: fix offset in skb copy handler
[linux-2.6-microblaze.git] / kernel / events / internal.h
index 2417eb5..486fd78 100644 (file)
@@ -123,18 +123,19 @@ static inline unsigned long perf_aux_size(struct ring_buffer *rb)
        return rb->aux_nr_pages << PAGE_SHIFT;
 }
 
-#define __DEFINE_OUTPUT_COPY_BODY(memcpy_func)                         \
+#define __DEFINE_OUTPUT_COPY_BODY(advance_buf, memcpy_func, ...)       \
 {                                                                      \
        unsigned long size, written;                                    \
                                                                        \
        do {                                                            \
                size    = min(handle->size, len);                       \
-               written = memcpy_func(handle->addr, buf, size);         \
+               written = memcpy_func(__VA_ARGS__);                     \
                written = size - written;                               \
                                                                        \
                len -= written;                                         \
                handle->addr += written;                                \
-               buf += written;                                         \
+               if (advance_buf)                                        \
+                       buf += written;                                 \
                handle->size -= written;                                \
                if (!handle->size) {                                    \
                        struct ring_buffer *rb = handle->rb;            \
@@ -153,12 +154,16 @@ static inline unsigned long perf_aux_size(struct ring_buffer *rb)
 static inline unsigned long                                            \
 func_name(struct perf_output_handle *handle,                           \
          const void *buf, unsigned long len)                           \
-__DEFINE_OUTPUT_COPY_BODY(memcpy_func)
+__DEFINE_OUTPUT_COPY_BODY(true, memcpy_func, handle->addr, buf, size)
 
 static inline unsigned long
 __output_custom(struct perf_output_handle *handle, perf_copy_f copy_func,
                const void *buf, unsigned long len)
-__DEFINE_OUTPUT_COPY_BODY(copy_func)
+{
+       unsigned long orig_len = len;
+       __DEFINE_OUTPUT_COPY_BODY(false, copy_func, handle->addr, buf,
+                                 orig_len - len, size)
+}
 
 static inline unsigned long
 memcpy_common(void *dst, const void *src, unsigned long n)