{pidfd,cgroup}-util: avoid alignment warning when accessing f_handle (#37520)
NetworkManager imports some systemd code, which we then build with
`-Wcast-align=strict`. This results in this warning:
```
../src/libnm-systemd-shared/src/basic/pidfd-util.c: In function 'pidfd_get_inode_id':
../src/libnm-systemd-shared/src/basic/pidfd-util.c:255:41: warning: cast increases required alignment of target type [-Wcast-align]
255 | *ret = *(uint64_t*) fh.file_handle.f_handle;
| ^
```
Since the address of `f_handle` should always be aligned at the word
boundary (it is preceded by 2 int`s` in `file_handle`), this patch uses
`CAST_ALIGN_PTR()` to avoid this warning.
This commit is contained in:
@@ -332,4 +332,4 @@ typedef union {
|
||||
.file_handle.handle_type = FILEID_KERNFS, \
|
||||
}
|
||||
|
||||
#define CG_FILE_HANDLE_CGROUPID(fh) (*(uint64_t*) (fh).file_handle.f_handle)
|
||||
#define CG_FILE_HANDLE_CGROUPID(fh) (*CAST_ALIGN_PTR(uint64_t, (fh).file_handle.f_handle))
|
||||
|
||||
@@ -248,7 +248,7 @@ int pidfd_get_inode_id(int fd, uint64_t *ret) {
|
||||
r = RET_NERRNO(name_to_handle_at(fd, "", &fh.file_handle, &mnt_id, AT_EMPTY_PATH));
|
||||
if (r >= 0) {
|
||||
if (ret)
|
||||
*ret = *(uint64_t*) fh.file_handle.f_handle;
|
||||
*ret = *CAST_ALIGN_PTR(uint64_t, fh.file_handle.f_handle);
|
||||
return 0;
|
||||
}
|
||||
assert(r != -EOVERFLOW);
|
||||
|
||||
Reference in New Issue
Block a user