]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tools/virtio: fix build for kmalloc_obj API and missing stubs
authorMichael S. Tsirkin <mst@redhat.com>
Wed, 3 Jun 2026 20:33:28 +0000 (16:33 -0400)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 10 Jun 2026 06:16:59 +0000 (02:16 -0400)
Add stubs for kmalloc_obj() and kmalloc_objs() to the tools/virtio
test harness, matching the new kernel allocator API. Also add the
DMA_ATTR_CPU_CACHE_CLEAN definition and include kernel.h from err.h
for the unlikely() macro.

Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <a0bd4b5bed56c49626c92a754d7aceab3325de25.1780520728.git.mst@redhat.com>

tools/virtio/linux/dma-mapping.h
tools/virtio/linux/err.h
tools/virtio/linux/kernel.h

index fddfa2fbb276a5ed7bde7b959075a8ee40781d8f..8d1a16cb20db40799461c557a44a4b1a25580bb4 100644 (file)
@@ -60,4 +60,6 @@ enum dma_data_direction {
  */
 #define DMA_MAPPING_ERROR              (~(dma_addr_t)0)
 
+#define DMA_ATTR_CPU_CACHE_CLEAN       (1UL << 11)
+
 #endif
index 0943c644a701a458f53b8ed2806114d40e872445..b7b4cb516dc9054b70f77162aeb05e0be540037c 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 #ifndef ERR_H
 #define ERR_H
+#include <linux/kernel.h>
 #define MAX_ERRNO      4095
 
 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
index 416d02703f614ebccc728b00f3554278e590c51a..104abf9d1aee5977e995e93f9a08b922e0f4e542 100644 (file)
@@ -65,6 +65,12 @@ static inline void *kmalloc_array(unsigned n, size_t s, gfp_t gfp)
        return kmalloc(n * s, gfp);
 }
 
+#define kmalloc_obj(VAR_OR_TYPE, ...) \
+       ((typeof(VAR_OR_TYPE) *)kmalloc(sizeof(typeof(VAR_OR_TYPE)), 0))
+
+#define kmalloc_objs(VAR_OR_TYPE, COUNT, ...) \
+       ((typeof(VAR_OR_TYPE) *)kmalloc(sizeof(typeof(VAR_OR_TYPE)) * (COUNT), 0))
+
 static inline void *kzalloc(size_t s, gfp_t gfp)
 {
        void *p = kmalloc(s, gfp);