imsm: introduce helpers to manage file descriptors
PATCH v2 1/1 imsm: introduce helpers to manage file descriptors
To avoid direct comparisions define dedicated inlines.
This patch propagates them in super-intel.c. They are declared globally for future usage outside IMSM.
Additionally, it adds fd check in save_backup_imsm() to remove code vulnerability and simplifies targets array implementation.
It also propagates pr_vrb() macro instead if (verbose) condidtion.
---
Changes:
- Fixed bug reported by Jes
- changed close_fd to do_close in __free_imsm_disk()
mdadm.h | 25 ++++++++ super-intel.c | 167 +++++++++++++++++++++++--------------------------- 2 files changed, 100 insertions(+), 92 deletions(-)
mdadm.h +25 -0
@@ -782,6 +782,31 @@ static inline char *map_dev(int major, int minor, int create)return map_dev_preferred (major, minor, create,NULL ); } +/** +* is_fd_valid() - check file descriptor. +* @fd: file descriptor. +* +* The function checks if @fd is nonnegative integer and shall be used only +* to verify open() result. +*/ +static inline int is_fd_valid (int fd) +{ +return (fd >-1 ); +} + +/** +* close_fd() - verify, close and unset file descriptor. +* @fd: pointer to file descriptor. +* +* The function closes and invalidates file descriptor if appropriative. It +* ignores incorrect file descriptor quitely to simplify error handling. +*/ +static inline void close_fd (int *fd) +{ +if (is_fd_valid (*fd) &&close (*fd) ==0 ) + *fd =-1 ; +} +struct active_array ;struct metadata_update ;
super-intel.c +75 -92
415 lines not on this page · raw message
Signature · 1 line
2.26.2
Jes Sorensen
AppliedQuoted 10 lines · Mariusz Tkaczyk
To avoid direct comparisions define dedicated inlines.
This patch propagates them insuper-intel.c. They are declared globally for future usage outside IMSM.Additionally, it adds fd check in
save_backup_imsm()to remove code vulnerability and simplifies targets array implementation.It also propagates
pr_vrb()macro instead if (verbose) condidtion.Signed-off-by Mariusz Tkaczyk <[email protected]>
Quoted 8 lines
---
Changes:
- Fixed bug reported by Jes
- changedclose_fdtodo_closein__free_imsm_disk()mdadm.h | 25 ++++++++ super-intel.c | 167 +++++++++++++++++++++++--------------------------- 2 files changed, 100 insertions(+), 92 deletions(-)
Applied!
Thanks,
Jes