From b31ee4be7739ccd8cf36048da212410514758949 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 14 Feb 2021 16:50:32 -0800 Subject: *fb: improve error propagation out of setup/init A lot of errors were being conflated as ENOMEM due to the lazy use of NULL pointer returns for errors. This commit reworks a handful of those return paths to instead return an errno-style int, storing the results on success at a supplied result pointer. It's kind of ugly, and I make some assumptions about libdrm setting errno on failure - it too uses this lazy API of returning NULL pointers on failure. Hopefully errno is always set by an underlying ioctl failing. The SDL error API is also pretty gross, being cross-platform it defines its own error codes so I try vaguely map these to errno values. I'm considering this a first approximation at fixing this up, but there are probably bugs as I did it real fast and nasty. It at least seems to all still work OK here in the non-error paths I tested. So it doesn't seem more broken than before at a glance. --- src/rototiller.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/rototiller.c') diff --git a/src/rototiller.c b/src/rototiller.c index 6857e72..84898da 100644 --- a/src/rototiller.c +++ b/src/rototiller.c @@ -440,8 +440,8 @@ int main(int argc, const char *argv[]) exit_if(!(rototiller.module = rototiller_lookup_module(settings_get_key(setup.module, 0))), "unable to lookup module from settings \"%s\"", settings_get_key(setup.module, 0)); - exit_if(!(rototiller.fb = fb_new(fb_ops, setup.video, NUM_FB_PAGES)), - "unable to create fb"); + exit_if((r = fb_new(fb_ops, setup.video, NUM_FB_PAGES, &rototiller.fb)) < 0, + "unable to create fb: %s", strerror(-r)); exit_if(!fps_setup(), "unable to setup fps counter"); -- cgit v1.2.1