This helper makes buffer allocation return standard error when
allocation failure.

Signed-off-by: Hongbo Li <[email protected]>
---
 fs/bcachefs/printbuf.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/bcachefs/printbuf.h b/fs/bcachefs/printbuf.h
index 1d570387b77f..73da89c9e419 100644
--- a/fs/bcachefs/printbuf.h
+++ b/fs/bcachefs/printbuf.h
@@ -139,6 +139,11 @@ void bch2_prt_bitflags_vector(struct printbuf *, const 
char * const[],
        .size   = _size,                                \
 })
 
+static inline int printbuf_err(struct printbuf *out)
+{
+       return out->allocation_failure ? -ENOMEM : 0;
+}
+
 /*
  * Returns size remaining of output buffer:
  */
-- 
2.34.1


Reply via email to