diff options
author | Jakub Kicinski <jakub.kicinski@netronome.com> | 2019-11-27 12:16:45 -0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-12-05 09:21:31 +0100 |
commit | 93c259c582afb5890f3d6d054160ba0aa5f78a2a (patch) | |
tree | 54593c9022e8027cb67bdbbd2b08cf2812dbb0b7 /tools | |
parent | 6ed8f48e6a535eec497b98ff13c17ccca1735432 (diff) | |
download | linux-stable-93c259c582afb5890f3d6d054160ba0aa5f78a2a.tar.gz linux-stable-93c259c582afb5890f3d6d054160ba0aa5f78a2a.tar.bz2 linux-stable-93c259c582afb5890f3d6d054160ba0aa5f78a2a.zip |
selftests: bpf: test_sockmap: handle file creation failures gracefully
[ Upstream commit 4b67c515036313f3c3ecba3cb2babb9cbddb3f85 ]
test_sockmap creates a temporary file to use for sendpage.
this may fail for various reasons. Handle the error rather
than segfault.
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/selftests/bpf/test_sockmap.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c index 0c7d9e556b47..a7fc91bb9119 100644 --- a/tools/testing/selftests/bpf/test_sockmap.c +++ b/tools/testing/selftests/bpf/test_sockmap.c @@ -248,6 +248,10 @@ static int msg_loop_sendpage(int fd, int iov_length, int cnt, int i, fp; file = fopen(".sendpage_tst.tmp", "w+"); + if (!file) { + perror("create file for sendpage"); + return 1; + } for (i = 0; i < iov_length * cnt; i++, k++) fwrite(&k, sizeof(char), 1, file); fflush(file); @@ -255,6 +259,11 @@ static int msg_loop_sendpage(int fd, int iov_length, int cnt, fclose(file); fp = open(".sendpage_tst.tmp", O_RDONLY); + if (fp < 0) { + perror("reopen file for sendpage"); + return 1; + } + clock_gettime(CLOCK_MONOTONIC, &s->start); for (i = 0; i < cnt; i++) { int sent = sendfile(fd, fp, NULL, iov_length); |