treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / tools / testing / selftests / android / ion / ionapp_import.c
blob54b580cb04f664ac98b271e5efe3465d17d0a8cc
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * ionapp_import.c
5 * It is a user space utility to receive android ion memory buffer fd
6 * over unix domain socket IPC that can be exported by ionapp_export.
7 * This acts like a client for ionapp_export.
9 * Copyright (C) 2017 Pintu Kumar <pintu.ping@gmail.com>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <string.h>
16 #include "ionutils.h"
17 #include "ipcsocket.h"
20 int main(void)
22 int ret, status;
23 int sockfd, shared_fd;
24 unsigned char *map_buf;
25 unsigned long map_len;
26 struct ion_buffer_info info;
27 struct socket_info skinfo;
29 /* This is the client part. Here 0 means client or importer */
30 status = opensocket(&sockfd, SOCKET_NAME, 0);
31 if (status < 0) {
32 fprintf(stderr, "No exporter exists...\n");
33 ret = status;
34 goto err_socket;
37 skinfo.sockfd = sockfd;
39 ret = socket_receive_fd(&skinfo);
40 if (ret < 0) {
41 fprintf(stderr, "Failed: socket_receive_fd\n");
42 goto err_recv;
45 shared_fd = skinfo.datafd;
46 printf("Received buffer fd: %d\n", shared_fd);
47 if (shared_fd <= 0) {
48 fprintf(stderr, "ERROR: improper buf fd\n");
49 ret = -1;
50 goto err_fd;
53 memset(&info, 0, sizeof(info));
54 info.buffd = shared_fd;
55 info.buflen = ION_BUFFER_LEN;
57 ret = ion_import_buffer_fd(&info);
58 if (ret < 0) {
59 fprintf(stderr, "Failed: ion_use_buffer_fd\n");
60 goto err_import;
63 map_buf = info.buffer;
64 map_len = info.buflen;
65 read_buffer(map_buf, map_len);
67 /* Write probably new data to the same buffer again */
68 map_len = ION_BUFFER_LEN;
69 write_buffer(map_buf, map_len);
71 err_import:
72 ion_close_buffer_fd(&info);
73 err_fd:
74 err_recv:
75 err_socket:
76 closesocket(sockfd, SOCKET_NAME);
78 return ret;