Skip to contentSkip to conversation

v4l-utils: fix potential crashing with 32-bit musl

PATCH In review Rosen Penev 2 participants 7 messages Jun 30, 2024 – Jul 2, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 v4l-utils: fix potential crashing with 32-bit musl

Under musl, if a format string has an integer followed by %s, a mismatch between types can cause the second half of the integer to be interpreted by %s.

Eg: printf("%d %s", 64bittype, string);

will crash, especially on 32-bit big endian.

The reason these are cast to uint64_t is because time_t and suseconds_t are 64-bit under musl, even on 32-bit platforms. uint64_t helps avoid any truncation issues that may or may not arise.

---
 utils/cec-follower/cec-follower.cpp | 3 ++-
 utils/libv4l2util/v4l2_driver.c     | 7 ++++---
 2 files changed, 6 insertions(+), 4 deletions(-)
utils/cec-follower/cec-follower.cpp +2 -1
index a7481aea..9b29e3c6 100644
@@ -3,6 +3,7 @@
  * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  */
 
+#include <cinttypes>
 #include <cstring>
 #include <ctime>
 #include <sstream>
@@ -354,7 +355,7 @@ void print_timers(struct node *node)
 			printf("source: %s, ", source.c_str());
 			if (t.recording_seq)
 				printf("rec-seq: 0x%x, ", t.recording_seq);
-			printf("needs: %ld %s\n", t.duration, "MB."); /* 1MB per second. */
+			printf("needs: %" PRIu64 " %s\n", (uint64_t)t.duration, "MB."); /* 1MB per second. */
 		}
 		printf("Total media space available for recording: ");
 		if (node->state.media_space_available >= 0)
utils/libv4l2util/v4l2_driver.c +4 -3
index 6b6366fa..5cd63fac 100644
@@ -15,6 +15,7 @@
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -174,13 +175,13 @@ static void prt_buf_info(char *name,struct v4l2_buffer *p)
 {
 	struct v4l2_timecode *tc=&p->timecode;
 
-	printf ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, "
+	printf ("%s: %02" PRIu64 ":%02d:%02d.%08" PRIu64 " index=%d, type=%s, "
 		"bytesused=%d, flags=0x%08x, "
 		"field=%s, sequence=%d, memory=%s, offset=0x%08x, length=%d\n",
-		name, (p->timestamp.tv_sec/3600),
+		name, (uint64_t)(p->timestamp.tv_sec/3600),
 		(int)(p->timestamp.tv_sec/60)%60,
 		(int)(p->timestamp.tv_sec%60),
-		p->timestamp.tv_usec,
+		(uint64_t)p->timestamp.tv_usec,
 		p->index,
 		prt_names(p->type,v4l2_type_names),
 		p->bytesused,p->flags,
Signature · 1 line
2.45.2
#1 lore raw

PATCH 2/4 v4l-utils: use 64-bit off_t format

musl uses 64-bit off_t by default on all platforms. Cast and fix format to work everywhere.

---
 utils/v4l2-tracer/retrace.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
utils/v4l2-tracer/retrace.cpp +1 -1
index 60d64d8b..010936c0 100644
@@ -72,7 +72,7 @@ void retrace_mmap(json_object *mmap_obj, bool is_mmap64)
 	                           (long) buf_address_retrace_pointer);
 
 	if (is_verbose() || (errno != 0)) {
-		fprintf(stderr, "fd: %d, offset: %ld, ", fd_retrace, off);
+		fprintf(stderr, "fd: %d, offset: %lld, ", fd_retrace, (long long)off);
 		if (is_mmap64)
 			perror("mmap64");
 		else
Signature · 1 line
2.45.2
#2 lore raw

PATCH 3/4 v4l-utils: use 64-bit formats for time

In reply to Rosen Penev

musl since version 1.2.0 uses 64-bit time_t and suseconds_t on all platforms, even 32-bit. Cast to avoid warnings and potentially future proof for when glibc and others gain support.

---
 utils/cec-compliance/cec-compliance.cpp   |  3 ++-
 utils/cec-compliance/cec-test-adapter.cpp |  5 +++--
 utils/cec-ctl/cec-ctl.cpp                 | 19 ++++++++++---------
 utils/cec-follower/cec-processing.cpp     |  3 ++-
 utils/keytable/keytable.c                 |  1 +
 5 files changed, 18 insertions(+), 13 deletions(-)
utils/cec-compliance/cec-compliance.cpp +2 -1
index 8075e1d6..df633a33 100644
@@ -3,6 +3,7 @@
  * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  */
 
+#include <cinttypes>
 #include <sstream>
 
 #include <fcntl.h>
@@ -279,7 +280,7 @@ static std::string ts2s(__u64 ts)
 	t = res.tv_sec;
 	s = ctime(&t);
 	s = s.substr(0, s.length() - 6);
-	sprintf(buf, "%03lu", res.tv_usec / 1000);
+	sprintf(buf, "%03" PRIu64, (uint64_t)res.tv_usec / 1000);
 	return s + "." + buf;
 }
 
utils/cec-compliance/cec-test-adapter.cpp +3 -2
index 08c856af..7a80d17b 100644
@@ -4,6 +4,7 @@
  */
 
 #include <cerrno>
+#include <cinttypes>
 #include <ctime>
 #include <string>
 
@@ -1276,9 +1277,9 @@ static int testLostMsgs(struct node *node)
 			printf("\t\tReceived messages: %d of which %d were CEC_MSG_CEC_VERSION\n",
 			       pending_rx_msgs, pending_rx_cec_version_msgs);
 		if (pending_quick_msgs < pending_msgs)
-			printf("\t\tReceived %d messages immediately, and %d over %ld seconds\n",
+			printf("\t\tReceived %d messages immediately, and %d over %" PRIu64 " seconds\n",
 			       pending_quick_msgs, pending_msgs - pending_quick_msgs,
-			       time(nullptr) - start);
+			       (uint64_t)time(nullptr) - start);
 	}
 	print_sfts(sft[1][1], "SFTs for repeating messages (>= 7)");
 	print_sfts(sft[1][0], "SFTs for repeating remote messages (>= 7)");
utils/cec-ctl/cec-ctl.cpp +10 -9
index 8848a49d..fb38320d 100644
@@ -6,6 +6,7 @@
 #include <algorithm>
 #include <cctype>
 #include <cerrno>
+#include <cinttypes>
 #include <cstring>
 #include <ctime>
 #include <map>
@@ -414,7 +415,7 @@ std::string ts2s(__u64 ts)
 		strftime(buf, sizeof(buf), "%a %b %e %T.000000", &tm);
 	}
 	secs = last_secs + t - last_t;
-	sprintf(buf + 14, "%02u:%02u.%06lu", secs / 60, secs % 60, res.tv_usec);
+	sprintf(buf + 14, "%02u:%02u.%06d", secs / 60, secs % 60, (int)res.tv_usec);
 	return buf;
 }
 
@@ -942,10 +943,10 @@ static void monitor(const struct node &node, __u32 monitor_time, const char *sto
 		}
 		fprintf(fstore, "# cec-ctl --store-pin\n");
 		fprintf(fstore, "# version %d\n", CEC_CTL_VERSION);
-		fprintf(fstore, "# start_monotonic %lu.%09lu\n",
-			start_monotonic.tv_sec, start_monotonic.tv_nsec);
-		fprintf(fstore, "# start_timeofday %lu.%06lu\n",
-			start_timeofday.tv_sec, start_timeofday.tv_usec);
+		fprintf(fstore, "# start_monotonic %" PRIu64 ".%09" PRIu64 "\n",
+			(uint64_t)start_monotonic.tv_sec, (uint64_t)start_monotonic.tv_nsec);
+		fprintf(fstore, "# start_timeofday %" PRIu64 ".%06" PRIu64 "\n",
+			(uint64_t)start_timeofday.tv_sec, (uint64_t)start_timeofday.tv_usec);
 		fprintf(fstore, "# log_addr_mask 0x%04x\n", node.log_addr_mask);
 		fprintf(fstore, "# phys_addr %x.%x.%x.%x\n",
 			cec_phys_addr_exp(node.phys_addr));
@@ -984,10 +985,10 @@ static void monitor(const struct node &node, __u32 monitor_time, const char *sto
 			 */
 			clock_gettime(CLOCK_MONOTONIC, &start_monotonic);
 			gettimeofday(&start_timeofday, nullptr);
-			fprintf(fstore, "# start_monotonic %lu.%09lu\n",
-				start_monotonic.tv_sec, start_monotonic.tv_nsec);
-			fprintf(fstore, "# start_timeofday %lu.%06lu\n",
-				start_timeofday.tv_sec, start_timeofday.tv_usec);
+			fprintf(fstore, "# start_monotonic %" PRIu64 ".%09" PRIu64 "\n",
+				(uint64_t)start_monotonic.tv_sec, (uint64_t)start_monotonic.tv_nsec);
+			fprintf(fstore, "# start_timeofday %" PRIu64 ".%06" PRIu64 "\n",
+				(uint64_t)start_timeofday.tv_sec, (uint64_t)start_timeofday.tv_usec);
 			fflush(fstore);
 			start_minute = now;
 		}
utils/cec-follower/cec-processing.cpp +2 -1
index 14ee211b..20c6165c 100644
@@ -4,6 +4,7 @@
  */
 
 #include <cerrno>
+#include <cinttypes>
 #include <ctime>
 #include <string>
 
@@ -72,7 +73,7 @@ static std::string ts2s(__u64 ts, bool wallclock)
 	t = res.tv_sec;
 	s = ctime(&t);
 	s = s.substr(0, s.length() - 6);
-	sprintf(buf, "%03lu", res.tv_usec / 1000);
+	sprintf(buf, "%03" PRIu64, (uint64_t)res.tv_usec / 1000);
 	return s + "." + buf;
 }
 
utils/keytable/keytable.c +1 -0
index b6474d5c..538f4ef3 100644
@@ -212,6 +212,7 @@ static enum sysfs_protocols parse_sysfs_protocol(const char *name, bool all_allo
 	return SYSFS_INVALID;
 }
 
+__attribute__((format(printf, 3, 0)))
 static void write_sysfs_protocols(enum sysfs_protocols protocols, FILE *fp, const char *fmt)
 {
 	const struct protocol_map_entry *pme;
Signature · 1 line
2.45.2
#3 lore raw

PATCH 4/4 v4l-utils: fix formats under ppc/mips64

In reply to Rosen Penev

Unlike libc, kernel headers use long long for 64-bit types. The exception is ppc64 and mips64, unless __SANE_USERSPACE_TYPES__ is defined.

Define in compiler.h and include before kernel headers are included so that wrong __u64 and __s64 definitions to not get used.

Fixes -Wformat warnings about llu being used instead of lu.

---
 contrib/xc3028-firmware/firmware-tool.c | 2 ++
 include/linux/compiler.h                | 1 +
 utils/cec-compliance/cec-compliance.h   | 2 ++
 utils/cec-ctl/cec-ctl.cpp               | 2 ++
 utils/cec-ctl/cec-ctl.h                 | 2 ++
 utils/cec-ctl/cec-pin.cpp               | 2 ++
 utils/cec-follower/cec-processing.cpp   | 2 ++
 utils/common/v4l2-info.h                | 2 ++
 utils/cx18-ctl/cx18-ctl.c               | 2 ++
 utils/ivtv-ctl/ivtv-ctl.c               | 2 ++
 utils/keytable/keytable.c               | 2 ++
 utils/media-ctl/media-ctl.c             | 2 ++
 utils/v4l2-compliance/v4l2-compliance.h | 2 ++
 utils/v4l2-ctl/v4l2-ctl-common.cpp      | 2 ++
 utils/v4l2-ctl/v4l2-ctl-streaming.cpp   | 2 ++
 utils/v4l2-ctl/v4l2-ctl.cpp             | 2 ++
 utils/v4l2-ctl/v4l2-ctl.h               | 2 ++
 utils/v4l2-dbg/v4l2-dbg.cpp             | 2 ++
 18 files changed, 35 insertions(+)
contrib/xc3028-firmware/firmware-tool.c +2 -0
index 5dd205e0..6bcb3237 100644
@@ -29,6 +29,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "linux/compiler.h"
+
 #include <asm/byteorder.h>
 #include <asm/types.h>
 
include/linux/compiler.h +1 -0
index 379629be..5a6326f8 100644
@@ -1,6 +1,7 @@
 #ifndef __linux_compiler_h
 #define __linux_compiler_h
 
+#define __SANE_USERSPACE_TYPES__
 #define __user
 
 #endif
utils/cec-compliance/cec-compliance.h +2 -0
index aae72842..d5bd1d0a 100644
@@ -8,6 +8,8 @@
 #ifndef _CEC_COMPLIANCE_H_
 #define _CEC_COMPLIANCE_H_
 
+#include "linux/compiler.h"
+
 #include <linux/cec-funcs.h>
 #include "cec-htng-funcs.h"
 
utils/cec-ctl/cec-ctl.cpp +2 -0
index fb38320d..a2ffcb2b 100644
@@ -21,6 +21,8 @@
 #include <sys/time.h>
 #include <unistd.h>
 
+#include "linux/compiler.h"
+
 #include <linux/cec-funcs.h>
 #include "cec-htng-funcs.h"
 #include "cec-log.h"
utils/cec-ctl/cec-ctl.h +2 -0
index 2c82bedc..e0692c31 100644
@@ -6,6 +6,8 @@
 #ifndef _CEC_CTL_H_
 #define _CEC_CTL_H_
 
+#include "linux/compiler.h"
+
 #include <cec-info.h>
 
 // cec-ctl.cpp
utils/cec-ctl/cec-pin.cpp +2 -0
index f3500555..0cdc19f7 100644
@@ -3,6 +3,8 @@
  * Copyright 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  */
 
+#include "linux/compiler.h"
+
 #include <string>
 
 #include <linux/cec.h>
utils/cec-follower/cec-processing.cpp +2 -0
index 20c6165c..cc38f143 100644
@@ -3,6 +3,8 @@
  * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  */
 
+#include "linux/compiler.h"
+
 #include <cerrno>
 #include <cinttypes>
 #include <ctime>
utils/common/v4l2-info.h +2 -0
index ac227971..eeb7bc6b 100644
@@ -8,6 +8,8 @@
 
 #include <string>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <linux/v4l2-subdev.h>
 
utils/cx18-ctl/cx18-ctl.c +2 -0
index 8586f72d..7c13b1a3 100644
@@ -34,6 +34,8 @@
 #include <sys/time.h>
 #include <math.h>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <v4l-getsubopt.h>
 
utils/ivtv-ctl/ivtv-ctl.c +2 -0
index b42b3489..bf36f40b 100644
@@ -34,6 +34,8 @@
 #include <sys/time.h>
 #include <math.h>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <v4l-getsubopt.h>
 
utils/keytable/keytable.c +2 -0
index 538f4ef3..ba7c7c4d 100644
@@ -12,6 +12,8 @@
    GNU General Public License for more details.
  */
 
+#include "linux/compiler.h"
+
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
utils/media-ctl/media-ctl.c +2 -0
index 33df0880..f91c1cfa 100644
@@ -34,6 +34,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 #include <linux/types.h>
 #include <linux/v4l2-mediabus.h>
utils/v4l2-compliance/v4l2-compliance.h +2 -0
index 3517bd07..2c2b2158 100644
@@ -26,6 +26,8 @@
 #include <string>
 #include <cstdint>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <linux/v4l2-subdev.h>
 #include <linux/media.h>
utils/v4l2-ctl/v4l2-ctl-common.cpp +2 -0
index 1f9cd0fb..ea120eb8 100644
@@ -9,6 +9,8 @@
 #include <sys/stat.h>
 #include <sys/sysmacros.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 
 #include "v4l2-ctl.h"
utils/v4l2-ctl/v4l2-ctl-streaming.cpp +2 -0
index 13bc057d..7af62ec8 100644
@@ -3,6 +3,8 @@
 #include <netdb.h>
 #include <sys/types.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 
 #include "compiler.h"
utils/v4l2-ctl/v4l2-ctl.cpp +2 -0
index a64fa514..d8a6c617 100644
@@ -27,6 +27,8 @@
 #include <getopt.h>
 #include <sys/epoll.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 
 #include "v4l2-ctl.h"
utils/v4l2-ctl/v4l2-ctl.h +2 -0
index a1911e80..fd1bd24a 100644
@@ -1,6 +1,8 @@
 #ifndef _V4L2_CTL_H
 #define _V4L2_CTL_H
 
+#include "linux/compiler.h"
+
 #include <cstdint>
 #include <linux/videodev2.h>
 #include <linux/v4l2-subdev.h>
utils/v4l2-dbg/v4l2-dbg.cpp +2 -0
index bd08b4cf..1b0d278a 100644
@@ -31,6 +31,8 @@
 #include <sys/klog.h>
 #endif
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <v4l-getsubopt.h>
 
Signature · 1 line
2.45.2
#4 lore raw

Re: [SPAM] [PATCH 4/4] v4l-utils: fix formats under ppc/mips64

Quoted 49 lines · Rosen Penev

Unlike libc, kernel headers use long long for 64-bit types. The exception is ppc64 and mips64, unless __SANE_USERSPACE_TYPES__ is defined.

Define in compiler.h and include before kernel headers are included so that wrong __u64 and __s64 definitions to not get used.

Fixes -Wformat warnings about llu being used instead of lu.

---
 contrib/xc3028-firmware/firmware-tool.c | 2 ++
 include/linux/compiler.h                | 1 +
 utils/cec-compliance/cec-compliance.h   | 2 ++
 utils/cec-ctl/cec-ctl.cpp               | 2 ++
 utils/cec-ctl/cec-ctl.h                 | 2 ++
 utils/cec-ctl/cec-pin.cpp               | 2 ++
 utils/cec-follower/cec-processing.cpp   | 2 ++
 utils/common/v4l2-info.h                | 2 ++
 utils/cx18-ctl/cx18-ctl.c               | 2 ++
 utils/ivtv-ctl/ivtv-ctl.c               | 2 ++
 utils/keytable/keytable.c               | 2 ++
 utils/media-ctl/media-ctl.c             | 2 ++
 utils/v4l2-compliance/v4l2-compliance.h | 2 ++
 utils/v4l2-ctl/v4l2-ctl-common.cpp      | 2 ++
 utils/v4l2-ctl/v4l2-ctl-streaming.cpp   | 2 ++
 utils/v4l2-ctl/v4l2-ctl.cpp             | 2 ++
 utils/v4l2-ctl/v4l2-ctl.h               | 2 ++
 utils/v4l2-dbg/v4l2-dbg.cpp             | 2 ++
 18 files changed, 35 insertions(+)
contrib/xc3028-firmware/firmware-tool.c +2 -0
index 5dd205e0..6bcb3237 100644
@@ -29,6 +29,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "linux/compiler.h"
+
 #include <asm/byteorder.h>
 #include <asm/types.h>
 
include/linux/compiler.h +0 -0
index 379629be..5a6326f8 100644

include/linux/compiler.h line 4

Quoted 4 lines
include/linux/compiler.h +1 -0
@@ -1,6 +1,7 @@
 #ifndef __linux_compiler_h
 #define __linux_compiler_h
 
+#define __SANE_USERSPACE_TYPES__

Please add a comment before this define, explaining why it is needed.

Basically the same as what you wrote in the commit log.

But this is in the wrong header: it should go into include/compiler.h. The linux/compiler.h header was used in just a single test application, and in fact it is no longer needed and has been effectively obsolete for quite a long time. I just removed it from v4l-utils.

Regards,

Hans

Quoted 211 lines
include/linux/compiler.h +0 -0
 #define __user
 
 #endif
utils/cec-compliance/cec-compliance.h +2 -0
index aae72842..d5bd1d0a 100644
@@ -8,6 +8,8 @@
 #ifndef _CEC_COMPLIANCE_H_
 #define _CEC_COMPLIANCE_H_
 
+#include "linux/compiler.h"
+
 #include <linux/cec-funcs.h>
 #include "cec-htng-funcs.h"
 
utils/cec-ctl/cec-ctl.cpp +2 -0
index fb38320d..a2ffcb2b 100644
@@ -21,6 +21,8 @@
 #include <sys/time.h>
 #include <unistd.h>
 
+#include "linux/compiler.h"
+
 #include <linux/cec-funcs.h>
 #include "cec-htng-funcs.h"
 #include "cec-log.h"
utils/cec-ctl/cec-ctl.h +2 -0
index 2c82bedc..e0692c31 100644
@@ -6,6 +6,8 @@
 #ifndef _CEC_CTL_H_
 #define _CEC_CTL_H_
 
+#include "linux/compiler.h"
+
 #include <cec-info.h>
 
 // cec-ctl.cpp
utils/cec-ctl/cec-pin.cpp +2 -0
index f3500555..0cdc19f7 100644
@@ -3,6 +3,8 @@
  * Copyright 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  */
 
+#include "linux/compiler.h"
+
 #include <string>
 
 #include <linux/cec.h>
utils/cec-follower/cec-processing.cpp +2 -0
index 20c6165c..cc38f143 100644
@@ -3,6 +3,8 @@
  * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  */
 
+#include "linux/compiler.h"
+
 #include <cerrno>
 #include <cinttypes>
 #include <ctime>
utils/common/v4l2-info.h +2 -0
index ac227971..eeb7bc6b 100644
@@ -8,6 +8,8 @@
 
 #include <string>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <linux/v4l2-subdev.h>
 
utils/cx18-ctl/cx18-ctl.c +2 -0
index 8586f72d..7c13b1a3 100644
@@ -34,6 +34,8 @@
 #include <sys/time.h>
 #include <math.h>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <v4l-getsubopt.h>
 
utils/ivtv-ctl/ivtv-ctl.c +2 -0
index b42b3489..bf36f40b 100644
@@ -34,6 +34,8 @@
 #include <sys/time.h>
 #include <math.h>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <v4l-getsubopt.h>
 
utils/keytable/keytable.c +2 -0
index 538f4ef3..ba7c7c4d 100644
@@ -12,6 +12,8 @@
    GNU General Public License for more details.
  */
 
+#include "linux/compiler.h"
+
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
utils/media-ctl/media-ctl.c +2 -0
index 33df0880..f91c1cfa 100644
@@ -34,6 +34,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 #include <linux/types.h>
 #include <linux/v4l2-mediabus.h>
utils/v4l2-compliance/v4l2-compliance.h +2 -0
index 3517bd07..2c2b2158 100644
@@ -26,6 +26,8 @@
 #include <string>
 #include <cstdint>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <linux/v4l2-subdev.h>
 #include <linux/media.h>
utils/v4l2-ctl/v4l2-ctl-common.cpp +2 -0
index 1f9cd0fb..ea120eb8 100644
@@ -9,6 +9,8 @@
 #include <sys/stat.h>
 #include <sys/sysmacros.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 
 #include "v4l2-ctl.h"
utils/v4l2-ctl/v4l2-ctl-streaming.cpp +2 -0
index 13bc057d..7af62ec8 100644
@@ -3,6 +3,8 @@
 #include <netdb.h>
 #include <sys/types.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 
 #include "compiler.h"
utils/v4l2-ctl/v4l2-ctl.cpp +2 -0
index a64fa514..d8a6c617 100644
@@ -27,6 +27,8 @@
 #include <getopt.h>
 #include <sys/epoll.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 
 #include "v4l2-ctl.h"
utils/v4l2-ctl/v4l2-ctl.h +2 -0
index a1911e80..fd1bd24a 100644
@@ -1,6 +1,8 @@
 #ifndef _V4L2_CTL_H
 #define _V4L2_CTL_H
 
+#include "linux/compiler.h"
+
 #include <cstdint>
 #include <linux/videodev2.h>
 #include <linux/v4l2-subdev.h>
utils/v4l2-dbg/v4l2-dbg.cpp +2 -0
index bd08b4cf..1b0d278a 100644
@@ -31,6 +31,8 @@
 #include <sys/klog.h>
 #endif
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <v4l-getsubopt.h>
 
#5 lore raw

Re: [SPAM] [PATCH 4/4] v4l-utils: fix formats under ppc/mips64

Quoted 58 lines · Hans Verkuil
Quoted 49 lines · Rosen Penev

Unlike libc, kernel headers use long long for 64-bit types. The exception is ppc64 and mips64, unless __SANE_USERSPACE_TYPES__ is defined.

Define in compiler.h and include before kernel headers are included so that wrong __u64 and __s64 definitions to not get used.

Fixes -Wformat warnings about llu being used instead of lu.

---
 contrib/xc3028-firmware/firmware-tool.c | 2 ++
 include/linux/compiler.h                | 1 +
 utils/cec-compliance/cec-compliance.h   | 2 ++
 utils/cec-ctl/cec-ctl.cpp               | 2 ++
 utils/cec-ctl/cec-ctl.h                 | 2 ++
 utils/cec-ctl/cec-pin.cpp               | 2 ++
 utils/cec-follower/cec-processing.cpp   | 2 ++
 utils/common/v4l2-info.h                | 2 ++
 utils/cx18-ctl/cx18-ctl.c               | 2 ++
 utils/ivtv-ctl/ivtv-ctl.c               | 2 ++
 utils/keytable/keytable.c               | 2 ++
 utils/media-ctl/media-ctl.c             | 2 ++
 utils/v4l2-compliance/v4l2-compliance.h | 2 ++
 utils/v4l2-ctl/v4l2-ctl-common.cpp      | 2 ++
 utils/v4l2-ctl/v4l2-ctl-streaming.cpp   | 2 ++
 utils/v4l2-ctl/v4l2-ctl.cpp             | 2 ++
 utils/v4l2-ctl/v4l2-ctl.h               | 2 ++
 utils/v4l2-dbg/v4l2-dbg.cpp             | 2 ++
 18 files changed, 35 insertions(+)
contrib/xc3028-firmware/firmware-tool.c +2 -0
index 5dd205e0..6bcb3237 100644
@@ -29,6 +29,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "linux/compiler.h"
+
 #include <asm/byteorder.h>
 #include <asm/types.h>
 
include/linux/compiler.h +0 -0
index 379629be..5a6326f8 100644

include/linux/compiler.h line 4

Quoted 4 lines
include/linux/compiler.h +1 -0
@@ -1,6 +1,7 @@
 #ifndef __linux_compiler_h
 #define __linux_compiler_h
 
+#define __SANE_USERSPACE_TYPES__

Please add a comment before this define, explaining why it is needed.

Quoted 6 lines

Basically the same as what you wrote in the commit log.

But this is in the wrong header: it should go into include/compiler.h. The linux/compiler.h header was used in just a single test application, and in fact it is no longer needed and has been effectively obsolete for quite a long time. I just removed it from v4l-utils.

I actually wonder if it would be better to add as a compile flag in meson.

Quoted 217 lines

Regards,

Hans

Quoted 211 lines
include/linux/compiler.h +0 -0
 #define __user
 
 #endif
utils/cec-compliance/cec-compliance.h +2 -0
index aae72842..d5bd1d0a 100644
@@ -8,6 +8,8 @@
 #ifndef _CEC_COMPLIANCE_H_
 #define _CEC_COMPLIANCE_H_
 
+#include "linux/compiler.h"
+
 #include <linux/cec-funcs.h>
 #include "cec-htng-funcs.h"
 
utils/cec-ctl/cec-ctl.cpp +2 -0
index fb38320d..a2ffcb2b 100644
@@ -21,6 +21,8 @@
 #include <sys/time.h>
 #include <unistd.h>
 
+#include "linux/compiler.h"
+
 #include <linux/cec-funcs.h>
 #include "cec-htng-funcs.h"
 #include "cec-log.h"
utils/cec-ctl/cec-ctl.h +2 -0
index 2c82bedc..e0692c31 100644
@@ -6,6 +6,8 @@
 #ifndef _CEC_CTL_H_
 #define _CEC_CTL_H_
 
+#include "linux/compiler.h"
+
 #include <cec-info.h>
 
 // cec-ctl.cpp
utils/cec-ctl/cec-pin.cpp +2 -0
index f3500555..0cdc19f7 100644
@@ -3,6 +3,8 @@
  * Copyright 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  */
 
+#include "linux/compiler.h"
+
 #include <string>
 
 #include <linux/cec.h>
utils/cec-follower/cec-processing.cpp +2 -0
index 20c6165c..cc38f143 100644
@@ -3,6 +3,8 @@
  * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  */
 
+#include "linux/compiler.h"
+
 #include <cerrno>
 #include <cinttypes>
 #include <ctime>
utils/common/v4l2-info.h +2 -0
index ac227971..eeb7bc6b 100644
@@ -8,6 +8,8 @@
 
 #include <string>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <linux/v4l2-subdev.h>
 
utils/cx18-ctl/cx18-ctl.c +2 -0
index 8586f72d..7c13b1a3 100644
@@ -34,6 +34,8 @@
 #include <sys/time.h>
 #include <math.h>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <v4l-getsubopt.h>
 
utils/ivtv-ctl/ivtv-ctl.c +2 -0
index b42b3489..bf36f40b 100644
@@ -34,6 +34,8 @@
 #include <sys/time.h>
 #include <math.h>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <v4l-getsubopt.h>
 
utils/keytable/keytable.c +2 -0
index 538f4ef3..ba7c7c4d 100644
@@ -12,6 +12,8 @@
    GNU General Public License for more details.
  */
 
+#include "linux/compiler.h"
+
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
utils/media-ctl/media-ctl.c +2 -0
index 33df0880..f91c1cfa 100644
@@ -34,6 +34,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 #include <linux/types.h>
 #include <linux/v4l2-mediabus.h>
utils/v4l2-compliance/v4l2-compliance.h +2 -0
index 3517bd07..2c2b2158 100644
@@ -26,6 +26,8 @@
 #include <string>
 #include <cstdint>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <linux/v4l2-subdev.h>
 #include <linux/media.h>
utils/v4l2-ctl/v4l2-ctl-common.cpp +2 -0
index 1f9cd0fb..ea120eb8 100644
@@ -9,6 +9,8 @@
 #include <sys/stat.h>
 #include <sys/sysmacros.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 
 #include "v4l2-ctl.h"
utils/v4l2-ctl/v4l2-ctl-streaming.cpp +2 -0
index 13bc057d..7af62ec8 100644
@@ -3,6 +3,8 @@
 #include <netdb.h>
 #include <sys/types.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 
 #include "compiler.h"
utils/v4l2-ctl/v4l2-ctl.cpp +2 -0
index a64fa514..d8a6c617 100644
@@ -27,6 +27,8 @@
 #include <getopt.h>
 #include <sys/epoll.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 
 #include "v4l2-ctl.h"
utils/v4l2-ctl/v4l2-ctl.h +2 -0
index a1911e80..fd1bd24a 100644
@@ -1,6 +1,8 @@
 #ifndef _V4L2_CTL_H
 #define _V4L2_CTL_H
 
+#include "linux/compiler.h"
+
 #include <cstdint>
 #include <linux/videodev2.h>
 #include <linux/v4l2-subdev.h>
utils/v4l2-dbg/v4l2-dbg.cpp +2 -0
index bd08b4cf..1b0d278a 100644
@@ -31,6 +31,8 @@
 #include <sys/klog.h>
 #endif
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <v4l-getsubopt.h>
 
#6 lore raw

Re: [SPAM] [PATCH 4/4] v4l-utils: fix formats under ppc/mips64

Quoted 59 lines · Rosen Penev
Quoted 58 lines · Hans Verkuil
Quoted 49 lines · Rosen Penev

Unlike libc, kernel headers use long long for 64-bit types. The exception is ppc64 and mips64, unless __SANE_USERSPACE_TYPES__ is defined.

Define in compiler.h and include before kernel headers are included so that wrong __u64 and __s64 definitions to not get used.

Fixes -Wformat warnings about llu being used instead of lu.

---
 contrib/xc3028-firmware/firmware-tool.c | 2 ++
 include/linux/compiler.h                | 1 +
 utils/cec-compliance/cec-compliance.h   | 2 ++
 utils/cec-ctl/cec-ctl.cpp               | 2 ++
 utils/cec-ctl/cec-ctl.h                 | 2 ++
 utils/cec-ctl/cec-pin.cpp               | 2 ++
 utils/cec-follower/cec-processing.cpp   | 2 ++
 utils/common/v4l2-info.h                | 2 ++
 utils/cx18-ctl/cx18-ctl.c               | 2 ++
 utils/ivtv-ctl/ivtv-ctl.c               | 2 ++
 utils/keytable/keytable.c               | 2 ++
 utils/media-ctl/media-ctl.c             | 2 ++
 utils/v4l2-compliance/v4l2-compliance.h | 2 ++
 utils/v4l2-ctl/v4l2-ctl-common.cpp      | 2 ++
 utils/v4l2-ctl/v4l2-ctl-streaming.cpp   | 2 ++
 utils/v4l2-ctl/v4l2-ctl.cpp             | 2 ++
 utils/v4l2-ctl/v4l2-ctl.h               | 2 ++
 utils/v4l2-dbg/v4l2-dbg.cpp             | 2 ++
 18 files changed, 35 insertions(+)
contrib/xc3028-firmware/firmware-tool.c +2 -0
index 5dd205e0..6bcb3237 100644
@@ -29,6 +29,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "linux/compiler.h"
+
 #include <asm/byteorder.h>
 #include <asm/types.h>
 
include/linux/compiler.h +0 -0
index 379629be..5a6326f8 100644

include/linux/compiler.h line 4

Quoted 4 lines
include/linux/compiler.h +1 -0
@@ -1,6 +1,7 @@
 #ifndef __linux_compiler_h
 #define __linux_compiler_h
 
+#define __SANE_USERSPACE_TYPES__

Please add a comment before this define, explaining why it is needed.

Quoted 7 lines
Quoted 6 lines

Basically the same as what you wrote in the commit log.

But this is in the wrong header: it should go into include/compiler.h. The linux/compiler.h header was used in just a single test application, and in fact it is no longer needed and has been effectively obsolete for quite a long time. I just removed it from v4l-utils.

I actually wonder if it would be better to add as a compile flag in meson.

I agree with that. I think I saw other projects do it like that, e.g.:

https://patchwork.yoctoproject.org/project/oe-core/patch/[email protected]/

Regards,

Hans

Quoted 217 lines
Quoted 217 lines

Regards,

Hans

Quoted 211 lines
include/linux/compiler.h +0 -0
 #define __user
 
 #endif
utils/cec-compliance/cec-compliance.h +2 -0
index aae72842..d5bd1d0a 100644
@@ -8,6 +8,8 @@
 #ifndef _CEC_COMPLIANCE_H_
 #define _CEC_COMPLIANCE_H_
 
+#include "linux/compiler.h"
+
 #include <linux/cec-funcs.h>
 #include "cec-htng-funcs.h"
 
utils/cec-ctl/cec-ctl.cpp +2 -0
index fb38320d..a2ffcb2b 100644
@@ -21,6 +21,8 @@
 #include <sys/time.h>
 #include <unistd.h>
 
+#include "linux/compiler.h"
+
 #include <linux/cec-funcs.h>
 #include "cec-htng-funcs.h"
 #include "cec-log.h"
utils/cec-ctl/cec-ctl.h +2 -0
index 2c82bedc..e0692c31 100644
@@ -6,6 +6,8 @@
 #ifndef _CEC_CTL_H_
 #define _CEC_CTL_H_
 
+#include "linux/compiler.h"
+
 #include <cec-info.h>
 
 // cec-ctl.cpp
utils/cec-ctl/cec-pin.cpp +2 -0
index f3500555..0cdc19f7 100644
@@ -3,6 +3,8 @@
  * Copyright 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  */
 
+#include "linux/compiler.h"
+
 #include <string>
 
 #include <linux/cec.h>
utils/cec-follower/cec-processing.cpp +2 -0
index 20c6165c..cc38f143 100644
@@ -3,6 +3,8 @@
  * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  */
 
+#include "linux/compiler.h"
+
 #include <cerrno>
 #include <cinttypes>
 #include <ctime>
utils/common/v4l2-info.h +2 -0
index ac227971..eeb7bc6b 100644
@@ -8,6 +8,8 @@
 
 #include <string>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <linux/v4l2-subdev.h>
 
utils/cx18-ctl/cx18-ctl.c +2 -0
index 8586f72d..7c13b1a3 100644
@@ -34,6 +34,8 @@
 #include <sys/time.h>
 #include <math.h>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <v4l-getsubopt.h>
 
utils/ivtv-ctl/ivtv-ctl.c +2 -0
index b42b3489..bf36f40b 100644
@@ -34,6 +34,8 @@
 #include <sys/time.h>
 #include <math.h>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <v4l-getsubopt.h>
 
utils/keytable/keytable.c +2 -0
index 538f4ef3..ba7c7c4d 100644
@@ -12,6 +12,8 @@
    GNU General Public License for more details.
  */
 
+#include "linux/compiler.h"
+
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
utils/media-ctl/media-ctl.c +2 -0
index 33df0880..f91c1cfa 100644
@@ -34,6 +34,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 #include <linux/types.h>
 #include <linux/v4l2-mediabus.h>
utils/v4l2-compliance/v4l2-compliance.h +2 -0
index 3517bd07..2c2b2158 100644
@@ -26,6 +26,8 @@
 #include <string>
 #include <cstdint>
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <linux/v4l2-subdev.h>
 #include <linux/media.h>
utils/v4l2-ctl/v4l2-ctl-common.cpp +2 -0
index 1f9cd0fb..ea120eb8 100644
@@ -9,6 +9,8 @@
 #include <sys/stat.h>
 #include <sys/sysmacros.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 
 #include "v4l2-ctl.h"
utils/v4l2-ctl/v4l2-ctl-streaming.cpp +2 -0
index 13bc057d..7af62ec8 100644
@@ -3,6 +3,8 @@
 #include <netdb.h>
 #include <sys/types.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 
 #include "compiler.h"
utils/v4l2-ctl/v4l2-ctl.cpp +2 -0
index a64fa514..d8a6c617 100644
@@ -27,6 +27,8 @@
 #include <getopt.h>
 #include <sys/epoll.h>
 
+#include "linux/compiler.h"
+
 #include <linux/media.h>
 
 #include "v4l2-ctl.h"
utils/v4l2-ctl/v4l2-ctl.h +2 -0
index a1911e80..fd1bd24a 100644
@@ -1,6 +1,8 @@
 #ifndef _V4L2_CTL_H
 #define _V4L2_CTL_H
 
+#include "linux/compiler.h"
+
 #include <cstdint>
 #include <linux/videodev2.h>
 #include <linux/v4l2-subdev.h>
utils/v4l2-dbg/v4l2-dbg.cpp +2 -0
index bd08b4cf..1b0d278a 100644
@@ -31,6 +31,8 @@
 #include <sys/klog.h>
 #endif
 
+#include "linux/compiler.h"
+
 #include <linux/videodev2.h>
 #include <v4l-getsubopt.h>