int fimc_is_video_streamoff(struct file *file, struct fimc_is_video_ctx *vctx, enum v4l2_buf_type type) { int ret = 0; u32 qcount; struct fimc_is_queue *queue; struct vb2_queue *vbq; struct fimc_is_framemgr *framemgr; BUG_ON(!file); BUG_ON(!vctx); if (!(vctx->state & BIT(FIMC_IS_VIDEO_START))) { err("[V%02d] invalid streamoff is requested(%lX)", vctx->video->id, vctx->state); return -EINVAL; } queue = GET_QUEUE(vctx); framemgr = &queue->framemgr; vbq = queue->vbq; if (!vbq) { merr("vbq is NULL", vctx); ret = -EINVAL; goto p_err; } framemgr_e_barrier_irq(framemgr, FMGR_IDX_0); qcount = framemgr->frame_req_cnt + framemgr->frame_pro_cnt + framemgr->frame_com_cnt; framemgr_x_barrier_irq(framemgr, FMGR_IDX_0); if (qcount > 0) mwarn("video%d stream off : queued buffer is not empty(%d)", vctx, vctx->video->id, qcount); if (vbq->type != type) { merr("invalid stream type(%d != %d)", vctx, vbq->type, type); ret = -EINVAL; goto p_err; } if (!vbq->streaming) { merr("streamoff: not streaming", vctx); ret = -EINVAL; goto p_err; } ret = vb2_streamoff(vbq, type); if (ret) { err("[V%02d] vb2_streamoff is fail(%d)", vctx->video->id, ret); goto p_err; } vctx->state = BIT(FIMC_IS_VIDEO_STOP); p_err: return ret; }
static int fimc_is_ischain_3ac_start(struct fimc_is_device_ischain *device, struct fimc_is_subdev *subdev, struct fimc_is_frame *frame, struct fimc_is_queue *queue, struct taa_param *taa_param, struct fimc_is_crop *otcrop, u32 *lindex, u32 *hindex, u32 *indexes) { int ret = 0; struct param_dma_output *dma_output; u32 hw_format, hw_bitwidth, hw_order; BUG_ON(!queue); BUG_ON(!queue->framecfg.format); hw_format = queue->framecfg.format->hw_format; hw_order = queue->framecfg.format->hw_order; hw_bitwidth = queue->framecfg.format->hw_bitwidth; /* memory width per pixel */ if ((otcrop->w != taa_param->otf_input.bayer_crop_width) || (otcrop->h != taa_param->otf_input.bayer_crop_height)) { merr("bds output size is invalid((%d, %d) != (%d, %d))", device, otcrop->w, otcrop->h, taa_param->otf_input.bayer_crop_width, taa_param->otf_input.bayer_crop_height); ret = -EINVAL; goto p_err; } if (otcrop->x || otcrop->y) { mwarn("crop pos(%d, %d) is ignored", device, otcrop->x, otcrop->y); otcrop->x = 0; otcrop->y = 0; } dma_output = fimc_is_itf_g_param(device, frame, subdev->param_dma_ot); dma_output->cmd = DMA_OUTPUT_COMMAND_ENABLE; dma_output->format = hw_format; dma_output->order = hw_order; dma_output->bitwidth = hw_bitwidth; dma_output->msb = hw_bitwidth - 1; dma_output->width = otcrop->w; dma_output->height = otcrop->h; dma_output->selection = 0; *lindex |= LOWBIT_OF(subdev->param_dma_ot); *hindex |= HIGHBIT_OF(subdev->param_dma_ot); (*indexes)++; subdev->output.crop = *otcrop; set_bit(FIMC_IS_SUBDEV_RUN, &subdev->state); p_err: return ret; }
static PSPAMResult_t handleOpenRequest(char *msgBuf) { char user[USERNAME_LEN], rhost[HOSTNAME_LEN]; pid_t pid, sid; struct passwd *spasswd; User_t *pamUser; PSPAMResult_t res = PSPAM_RES_DENY; char *ptr = msgBuf; /* ensure we use the same byteorder as the PAM module */ bool byteOrder = setByteOrder(true); /* get ssh pid */ getPid(&ptr, &pid); /* get ssh sid */ getPid(&ptr, &sid); /* get pam username */ getString(&ptr, user, sizeof(user)); /* get pam rhost */ getString(&ptr, rhost, sizeof(rhost)); /* reset psserial's byteorder */ setByteOrder(byteOrder); mdbg(PSPAM_LOG_DEBUG, "%s: got pam request user: '******' pid: %i sid: %i" " rhost: '%s'\n", __func__, user, pid, sid, rhost); errno = 0; spasswd = getpwnam(user); if (!spasswd && errno) mwarn(errno, "%s: getpwnam(%s)", __func__, user); pamUser = findUser(user, NULL); /* Determine user's allowance */ if (spasswd && isPSAdminUser(spasswd->pw_uid, spasswd->pw_gid)) { res = PSPAM_RES_ADMIN_USER; } else if (pamUser) { if (pamUser->state == PSPAM_STATE_PROLOGUE) { res = PSPAM_RES_PROLOG; } else { res = PSPAM_RES_BATCH; addSession(user, rhost, pid, sid); } } mdbg(PSPAM_LOG_DEBUG, "%s: reply to user '%s' rhost '%s': %i\n", __func__, user, rhost, res); return res; }
static int setupPAMSock(char *sName) { struct sockaddr_un sa; int sock = -1, opt = 1; char *pSName = sName[0] ? sName : sName + 1; sock = socket(PF_UNIX, SOCK_STREAM, 0); if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0 ) { mwarn(errno, "%s: setsockopt(%i)", __func__, sock); } /* bind the socket to the right address */ memset(&sa, 0, sizeof(sa)); sa.sun_family = AF_UNIX; if (sName[0] == '\0') { sa.sun_path[0] = '\0'; strncpy(sa.sun_path+1, sName+1, sizeof(sa.sun_path)-1); } else { strncpy(sa.sun_path, sName, sizeof(sa.sun_path)); unlink(sName); } if (bind(sock, (struct sockaddr *)&sa, sizeof(sa)) < 0) { mwarn(errno, "%s: bind(%s%s)", __func__, sName[0] ? "":"\\0", pSName); close(sock); return -1; } if (sName[0]) chmod(sa.sun_path, S_IRWXU); if (listen(sock, 20) < 0) { mwarn(errno, "%s: listen(%s%s)", __func__, sName[0] ? "":"\\0", pSName); close(sock); return -1; } return sock; }
int fimc_is_video_streamoff(struct file *file, struct fimc_is_video_ctx *vctx, enum v4l2_buf_type type) { int ret = 0; u32 qcount; struct fimc_is_queue *queue; struct vb2_queue *vbq; struct fimc_is_framemgr *framemgr; BUG_ON(!file); BUG_ON(!vctx); queue = GET_QUEUE(vctx, type); framemgr = &queue->framemgr; vbq = queue->vbq; if (!vbq) { merr("vbq is NULL", vctx); ret = -EINVAL; goto p_err; } framemgr_e_barrier_irq(framemgr, 0); qcount = framemgr->frame_req_cnt + framemgr->frame_pro_cnt + framemgr->frame_com_cnt; framemgr_x_barrier_irq(framemgr, 0); if (qcount > 0) mwarn("video%d stream off : queued buffer is not empty(%d)", vctx, vctx->video->id, qcount); if (vbq->type != type) { merr("invalid stream type(%d != %d)", vctx, vbq->type, type); ret = -EINVAL; goto p_err; } if (!vbq->streaming) { merr("streamoff: not streaming", vctx); ret = -EINVAL; goto p_err; } ret = vb2_streamoff(vbq, type); p_err: return ret; }
static int handleMasterSocket(int sock, void *empty) { /* accept new tcp connection */ struct sockaddr_in SAddr; unsigned int clientlen = sizeof(SAddr); int clientSock = accept(sock, (void *)&SAddr, &clientlen); if (clientSock == -1) { mwarn(errno, "%s accept(%i) failed: ", __func__, sock); return 0; } Selector_register(clientSock, handlePamRequest, NULL); return 0; }
static int fimc_is_sen_video_s_ctrl(struct file *file, void *priv, struct v4l2_control *ctrl) { int ret = 0; struct fimc_is_video_ctx *vctx = file->private_data; struct fimc_is_device_sensor *device; struct v4l2_subdev *subdev_flite; BUG_ON(!ctrl); BUG_ON(!vctx); device = vctx->device; if (!device) { err("device is NULL"); ret = -EINVAL; goto p_err; } subdev_flite = device->subdev_flite; if (!subdev_flite) { err("subdev_flite is NULL"); ret = -EINVAL; goto p_err; } switch (ctrl->id) { case V4L2_CID_IS_S_STREAM: { u32 sstream, instant, noblock; sstream = (ctrl->value & SENSOR_SSTREAM_MASK) >> SENSOR_SSTREAM_SHIFT; instant = (ctrl->value & SENSOR_INSTANT_MASK) >> SENSOR_INSTANT_SHIFT; noblock = (ctrl->value & SENSOR_NOBLOCK_MASK) >> SENSOR_NOBLOCK_SHIFT; /* * nonblock(0) : blocking command * nonblock(1) : non-blocking command */ if (sstream == IS_ENABLE_STREAM) { ret = fimc_is_sensor_front_start(device, instant, noblock); if (ret) { merr("fimc_is_sensor_front_start is fail(%d)", device, ret); goto p_err; } } else { ret = fimc_is_sensor_front_stop(device); if (ret) { merr("fimc_is_sensor_front_stop is fail(%d)", device, ret); goto p_err; } } } break; case V4L2_CID_IS_S_BNS: if (device->pdata->is_bns == false) { mwarn("Could not support BNS\n", device); goto p_err; } ret = fimc_is_sensor_s_bns(device, ctrl->value); if (ret) { merr("fimc_is_sensor_s_bns is fail(%d)", device, ret); goto p_err; } ret = v4l2_subdev_call(subdev_flite, core, s_ctrl, ctrl); if (ret) { merr("v4l2_flite_call(s_ctrl) is fail(%d)", device, ret); goto p_err; } break; /* * gain boost: min_target_fps, max_target_fps, scene_mode */ case V4L2_CID_IS_MIN_TARGET_FPS: if (test_bit(FIMC_IS_SENSOR_FRONT_START, &device->state)) { err("failed to set min_target_fps: %d - sensor stream on already\n", ctrl->value); ret = -EINVAL; } else { device->min_target_fps = ctrl->value; } break; case V4L2_CID_IS_MAX_TARGET_FPS: if (test_bit(FIMC_IS_SENSOR_FRONT_START, &device->state)) { err("failed to set max_target_fps: %d - sensor stream on already\n", ctrl->value); ret = -EINVAL; } else { device->max_target_fps = ctrl->value; } break; case V4L2_CID_IS_SCENE_MODE: if (test_bit(FIMC_IS_SENSOR_FRONT_START, &device->state)) { err("failed to set scene_mode: %d - sensor stream on already\n", ctrl->value); ret = -EINVAL; } else { device->scene_mode = ctrl->value; } break; case V4L2_CID_SENSOR_SET_FRAME_RATE: if (fimc_is_sensor_s_frame_duration(device, ctrl->value)) { err("failed to set frame duration : %d\n - %d", ctrl->value, ret); ret = -EINVAL; } break; case V4L2_CID_SENSOR_SET_AE_TARGET: if (fimc_is_sensor_s_exposure_time(device, ctrl->value)) { err("failed to set exposure time : %d\n - %d", ctrl->value, ret); ret = -EINVAL; } break; default: ret = fimc_is_sensor_s_ctrl(device, ctrl); if (ret) { err("invalid ioctl(0x%08X) is requested", ctrl->id); ret = -EINVAL; goto p_err; } break; } p_err: return ret; }
FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size) { FAR struct mm_freenode_s *node; void *ret = NULL; int ndx; /* Handle bad sizes */ if (size < 1) { return NULL; } /* Adjust the size to account for (1) the size of the allocated node and * (2) to make sure that it is an even multiple of our granule size. */ size = MM_ALIGN_UP(size + SIZEOF_MM_ALLOCNODE); /* We need to hold the MM semaphore while we muck with the nodelist. */ mm_takesemaphore(heap); /* Get the location in the node list to start the search. Special case * really big allocations */ if (size >= MM_MAX_CHUNK) { ndx = MM_NNODES-1; } else { /* Convert the request size into a nodelist index */ ndx = mm_size2ndx(size); } /* Search for a large enough chunk in the list of nodes. This list is * ordered by size, but will have occasional zero sized nodes as we visit * other mm_nodelist[] entries. */ for (node = heap->mm_nodelist[ndx].flink; node && node->size < size; node = node->flink); /* If we found a node with non-zero size, then this is one to use. Since * the list is ordered, we know that is must be best fitting chunk * available. */ if (node) { FAR struct mm_freenode_s *remainder; FAR struct mm_freenode_s *next; size_t remaining; /* Remove the node. There must be a predecessor, but there may not be * a successor node. */ DEBUGASSERT(node->blink); node->blink->flink = node->flink; if (node->flink) { node->flink->blink = node->blink; } /* Check if we have to split the free node into one of the allocated * size and another smaller freenode. In some cases, the remaining * bytes can be smaller (they may be SIZEOF_MM_ALLOCNODE). In that * case, we will just carry the few wasted bytes at the end of the * allocation. */ remaining = node->size - size; if (remaining >= SIZEOF_MM_FREENODE) { /* Get a pointer to the next node in physical memory */ next = (FAR struct mm_freenode_s *)(((FAR char *)node) + node->size); /* Create the remainder node */ remainder = (FAR struct mm_freenode_s *)(((FAR char *)node) + size); remainder->size = remaining; remainder->preceding = size; /* Adjust the size of the node under consideration */ node->size = size; /* Adjust the 'preceding' size of the (old) next node, preserving * the allocated flag. */ next->preceding = remaining | (next->preceding & MM_ALLOC_BIT); /* Add the remainder back into the nodelist */ mm_addfreechunk(heap, remainder); } /* Handle the case of an exact size match */ node->preceding |= MM_ALLOC_BIT; ret = (void *)((FAR char *)node + SIZEOF_MM_ALLOCNODE); } mm_givesemaphore(heap); /* If CONFIG_DEBUG_MM is defined, then output the result of the allocation * to the SYSLOG. */ #ifdef CONFIG_DEBUG_MM if (!ret) { mwarn("WARNING: Allocation failed, size %d\n", size); } else { minfo("Allocated %p, size %d\n", ret, size); } #endif return ret; }
static void login_request_cb(conn *c, unsigned char *msg, size_t sz) { Connection_T dbc = ConnectionPool_getConnection(pool); if (NULL == dbc) { mwarn("ConnectionPool_getConnection failed!"); return; } TRY { /* check account && passwd */ login::login_request lr; msg_body<login::login_request>(msg, sz, &lr); ResultSet_T result = Connection_executeQuery(dbc, "SELECT `id` FROM `profile` WHERE `account`='%s' AND `passwd`='%s';", lr.account().c_str(), lr.passwd().c_str()); if (ResultSet_next(result)) { uint64_t uid = ResultSet_getLLong(result, 1); login::error err = login::success; do { int tempid = user_manager_t::get_guid(); user_t *user = (user_t *)malloc(sizeof(user_t)); if (NULL == user) { mdebug("user_t alloc failed!"); err = login::unknow; break; } user->id = tempid; user->c = NULL; user->refcnt = 1; pthread_mutex_init(&user->lock, NULL); if (0 > user_mgr->add_user(user)) { mdebug("add_user failed!"); err = login::unknow; break; } user_lock(user); user->c = c; user_unlock(user); conn_lock(c); c->user = user; conn_unlock(c); /* tell center */ login::user_login_request ulr; ulr.set_tempid(tempid); ulr.set_uid(uid); center_info_t *info = center_info_mgr->get_center_info_incref(1); if (info) { conn_write<login::user_login_request>(info->c, le_user_login_request, &ulr); center_info_decref(info); } return; } while (0); login::login_reply lr; lr.set_err(err); conn_write<login::login_reply>(c, lc_login_reply, &lr); } else { login::login_reply lr; lr.set_err(login::auth); conn_write<login::login_reply>(c, lc_login_reply, &lr); } } CATCH(SQLException) { merror("SQLException -- %s", Exception_frame.message); } FINALLY { Connection_close(dbc); } END_TRY; }