void mq_desblockalloc(void) { FAR struct mq_des_block_s *mqdesblock; /* Allocate a block of message descriptors */ mqdesblock = (FAR struct mq_des_block_s *)kmm_malloc(sizeof(struct mq_des_block_s)); if (mqdesblock) { int i; /* Add the block to the list of allocated blocks (in case * we ever need to reclaim the memory. */ sq_addlast((FAR sq_entry_t*)&mqdesblock->queue, &g_desalloc); /* Then add each message queue descriptor to the free list */ for (i = 0; i < NUM_MSG_DESCRIPTORS; i++) { sq_addlast((FAR sq_entry_t*)&mqdesblock->mqdes[i], &g_desfree); } } }
int kxtj9_driver_init(){ int ret = 0; if (g_data != NULL) goto init_done; g_data = kmm_malloc(sizeof(struct kxtj9_data)); memset(g_data, 0, sizeof(struct kxtj9_data)); g_data->i2c = up_i2cinitialize(CONFIG_SENSOR_KXTJ9_I2C_BUS); if (!g_data->i2c) { dbg("failed to init i2c\n"); ret = -ENODEV; goto init_done; } ret = I2C_SETADDRESS(g_data->i2c, KXTJ9_I2C_ADDR, 7); if (ret) { dbg("failed to set i2c address\n"); goto init_done; } I2C_SETFREQUENCY(g_data->i2c, CONFIG_SENSOR_KXTJ9_I2C_BUS_SPEED); init_done: return ret; }
FAR struct pipe_dev_s *pipecommon_allocdev(size_t bufsize) { FAR struct pipe_dev_s *dev; DEBUGASSERT(bufsize <= CONFIG_DEV_PIPE_MAXSIZE); /* Allocate a private structure to manage the pipe */ dev = (FAR struct pipe_dev_s *)kmm_malloc(sizeof(struct pipe_dev_s)); if (dev) { /* Initialize the private structure */ memset(dev, 0, sizeof(struct pipe_dev_s)); sem_init(&dev->d_bfsem, 0, 1); sem_init(&dev->d_rdsem, 0, 0); sem_init(&dev->d_wrsem, 0, 0); /* The read/write wait semaphores are used for signaling and, hence, * should not have priority inheritance enabled. */ sem_setprotocol(&dev->d_rdsem, SEM_PRIO_NONE); sem_setprotocol(&dev->d_wrsem, SEM_PRIO_NONE); dev->d_bufsize = bufsize; } return dev; }
static int proc_dup(FAR const struct file *oldp, FAR struct file *newp) { FAR struct proc_file_s *oldfile; FAR struct proc_file_s *newfile; fvdbg("Dup %p->%p\n", oldp, newp); /* Recover our private data from the old struct file instance */ oldfile = (FAR struct proc_file_s *)oldp->f_priv; DEBUGASSERT(oldfile); /* Allocate a new container to hold the task and node selection */ newfile = (FAR struct proc_file_s *)kmm_malloc(sizeof(struct proc_file_s)); if (!newfile) { fdbg("ERROR: Failed to allocate file container\n"); return -ENOMEM; } /* The copy the file information from the old container to the new */ memcpy(newfile, oldfile, sizeof(struct proc_file_s)); /* Save the new container in the new file structure */ newp->f_priv = (FAR void *)newfile; return OK; }
int lm75_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, uint8_t addr) { FAR struct lm75_dev_s *priv; int ret; /* Initialize the LM-75 device structure */ priv = (FAR struct lm75_dev_s *)kmm_malloc(sizeof(struct lm75_dev_s)); if (!priv) { lm75dbg("Failed to allocate instance\n"); return -ENOMEM; } priv->i2c = i2c; priv->addr = addr; priv->fahrenheit = false; /* Register the character driver */ ret = register_driver(devpath, &g_lm75fops, 0666, priv); if (ret < 0) { lm75dbg("Failed to register driver: %d\n", ret); kmm_free(priv); } return ret; }
int mb7040_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, uint8_t addr) { FAR struct mb7040_dev_s *priv; int ret; /* Sanity check */ DEBUGASSERT(i2c != NULL); /* Initialize the device's structure */ priv = (FAR struct mb7040_dev_s *)kmm_malloc(sizeof(*priv)); if (priv == NULL) { sndbg("Failed to allocate instance\n"); return -ENOMEM; } priv->i2c = i2c; priv->addr = addr; /* Register the character driver */ ret = register_driver(devpath, &g_fops, 0666, priv); if (ret < 0) { sndbg("Failed to register driver: %d\n", ret); kmm_free(priv); } return ret; }
static int uptime_dup(FAR const struct file *oldp, FAR struct file *newp) { FAR struct uptime_file_s *oldattr; FAR struct uptime_file_s *newattr; finfo("Dup %p->%p\n", oldp, newp); /* Recover our private data from the old struct file instance */ oldattr = (FAR struct uptime_file_s *)oldp->f_priv; DEBUGASSERT(oldattr); /* Allocate a new container to hold the task and attribute selection */ newattr = (FAR struct uptime_file_s *)kmm_malloc(sizeof(struct uptime_file_s)); if (!newattr) { ferr("ERROR: Failed to allocate file attributes\n"); return -ENOMEM; } /* The copy the file attributes from the old attributes to the new */ memcpy(newattr, oldattr, sizeof(struct uptime_file_s)); /* Save the new attributes in the new file structure */ newp->f_priv = (FAR void *)newattr; return OK; }
static struct mqueue_msg_s * mq_msgblockalloc(FAR sq_queue_t *queue, uint16_t nmsgs, uint8_t alloc_type) { struct mqueue_msg_s *mqmsgblock; /* The g_msgfree must be loaded at initialization time to hold the * configured number of messages. */ mqmsgblock = (FAR struct mqueue_msg_s*) kmm_malloc(sizeof(struct mqueue_msg_s) * nmsgs); if (mqmsgblock) { struct mqueue_msg_s *mqmsg = mqmsgblock; int i; for (i = 0; i < nmsgs; i++) { mqmsg->type = alloc_type; sq_addlast((FAR sq_entry_t*)mqmsg++, queue); } } return mqmsgblock; }
int max6675_register(FAR const char *devpath, FAR struct spi_dev_s *spi) { FAR struct max6675_dev_s *priv; int ret; /* Sanity check */ DEBUGASSERT(spi != NULL); /* Initialize the MAX6675 device structure */ priv = (FAR struct max6675_dev_s *)kmm_malloc(sizeof(struct max6675_dev_s)); if (priv == NULL) { snerr("ERROR: Failed to allocate instance\n"); return -ENOMEM; } priv->spi = spi; priv->temp = 0; /* Register the character driver */ ret = register_driver(devpath, &g_max6675fops, 0666, priv); if (ret < 0) { snerr("ERROR: Failed to register driver: %d\n", ret); kmm_free(priv); } return ret; }
FAR void *group_malloc(FAR struct task_group_s *group, size_t nbytes) { /* A NULL group pointer means the current group */ if (!group) { FAR struct tcb_s *tcb = this_task(); DEBUGASSERT(tcb && tcb->group); group = tcb->group; } /* Check the group type */ if ((group->tg_flags & GROUP_FLAG_PRIVILEGED) != 0) { /* It is a privileged group... use the kernel mode memory allocator */ return kmm_malloc(nbytes); } else { /* This is an unprivileged group... use the user mode memory * allocator. */ return kumm_malloc(nbytes); } }
static int dm320_allocvideomemory(void) { #ifndef CONFIG_DM320_VID0_DISABLE #ifndef CONFIG_DM320_DISABLE_PINGPONG g_vid0base = (FAR void *)kmm_malloc(2 * DM320_VID0_FBLEN); g_vid0ppbase = (FAR char *)g_vid0base + DM320_VID0_FBLEN; #else g_vid0base = (FAR void *)kmm_malloc(DM320_VID0_FBLEN); #endif if (!g_vid0base) { goto errout; } #endif #ifndef CONFIG_DM320_VID1_DISABLE g_vid1base = (FAR void *)kmm_malloc(DM320_VID1_FBLEN); if (!g_vid1base) { goto errout; } #endif #ifndef CONFIG_DM320_OSD0_DISABLE g_osd0base = (FAR void *)kmm_malloc(DM320_OSD0_FBLEN); if (!g_osd0base) { goto errout; } #endif #ifndef CONFIG_DM320_OSD1_DISABLE g_osd1base = (FAR void *)kmm_malloc(DM320_OSD1_FBLEN); if (!g_osd1base) { goto errout; } #endif return OK; errout: dm320_freevideomemory(); return -ENOMEM; }
int group_initialize(FAR struct task_tcb_s *tcb) { FAR struct task_group_s *group; #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) irqstate_t flags; #endif DEBUGASSERT(tcb && tcb->cmn.group); group = tcb->cmn.group; #ifdef HAVE_GROUP_MEMBERS /* Allocate space to hold GROUP_INITIAL_MEMBERS members of the group */ group->tg_members = (FAR pid_t *)kmm_malloc(GROUP_INITIAL_MEMBERS*sizeof(pid_t)); if (!group->tg_members) { kmm_free(group); return -ENOMEM; } /* Assign the PID of this new task as a member of the group. */ group->tg_members[0] = tcb->cmn.pid; /* Initialize the non-zero elements of group structure and assign it to * the tcb. */ group->tg_mxmembers = GROUP_INITIAL_MEMBERS; /* Number of members in allocation */ #endif #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) /* Add the initialized entry to the list of groups */ flags = irqsave(); group->flink = g_grouphead; g_grouphead = group; irqrestore(flags); #endif /* Save the ID of the main task within the group of threads. This needed * for things like SIGCHILD. It ID is also saved in the TCB of the main * task but is also retained in the group which may persist after the main * task has exited. */ #if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SCHED_HAVE_PARENT) group->tg_task = tcb->cmn.pid; #endif /* Mark that there is one member in the group, the main task */ group->tg_nmembers = 1; return OK; }
static inline FAR struct usbhost_state_s *usbhost_allocclass(void) { FAR struct usbhost_state_s *priv; DEBUGASSERT(!up_interrupt_context()); priv = (FAR struct usbhost_state_s *)kmm_malloc(sizeof(struct usbhost_state_s)); uvdbg("Allocated: %p\n", priv); return priv; }
static FAR sigpendq_t *sig_allocatependingsignal(void) { FAR sigpendq_t *sigpend; irqstate_t flags; /* Check if we were called from an interrupt handler. */ if (up_interrupt_context()) { /* Try to get the pending signal structure from the free list */ sigpend = (FAR sigpendq_t *)sq_remfirst(&g_sigpendingsignal); if (!sigpend) { /* If no pending signal structure is available in the free list, * then try the special list of structures reserved for * interrupt handlers */ sigpend = (FAR sigpendq_t *)sq_remfirst(&g_sigpendingirqsignal); } } /* If we were not called from an interrupt handler, then we are * free to allocate pending action structures if necessary. */ else { /* Try to get the pending signal structure from the free list */ flags = enter_critical_section(); sigpend = (FAR sigpendq_t *)sq_remfirst(&g_sigpendingsignal); leave_critical_section(flags); /* Check if we got one. */ if (!sigpend) { /* No... Allocate the pending signal */ if (!sigpend) { sigpend = (FAR sigpendq_t *)kmm_malloc((sizeof (sigpendq_t))); } /* Check if we got an allocated message */ if (sigpend) { sigpend->type = SIG_ALLOC_DYN; } } } return sigpend; }
FAR struct mqueue_msg_s *mq_msgalloc(void) { FAR struct mqueue_msg_s *mqmsg; irqstate_t flags; /* If we were called from an interrupt handler, then try to get the message * from generally available list of messages. If this fails, then try the * list of messages reserved for interrupt handlers */ if (up_interrupt_context()) { /* Try the general free list */ mqmsg = (FAR struct mqueue_msg_s *)sq_remfirst(&g_msgfree); if (mqmsg == NULL) { /* Try the free list reserved for interrupt handlers */ mqmsg = (FAR struct mqueue_msg_s *)sq_remfirst(&g_msgfreeirq); } } /* We were not called from an interrupt handler. */ else { /* Try to get the message from the generally available free list. * Disable interrupts -- we might be called from an interrupt handler. */ flags = enter_critical_section(); mqmsg = (FAR struct mqueue_msg_s *)sq_remfirst(&g_msgfree); leave_critical_section(flags); /* If we cannot a message from the free list, then we will have to * allocate one. */ if (mqmsg == NULL) { mqmsg = (FAR struct mqueue_msg_s *) kmm_malloc((sizeof (struct mqueue_msg_s))); /* Check if we allocated the message */ if (mqmsg != NULL) { /* Yes... remember that this message was dynamically allocated */ mqmsg->type = MQ_ALLOC_DYN; } } } return mqmsg; }
FAR sigq_t *sig_allocatependingsigaction(void) { FAR sigq_t *sigq; irqstate_t saved_state; /* Check if we were called from an interrupt handler. */ if (up_interrupt_context()) { /* Try to get the pending signal action structure from the free list */ sigq = (FAR sigq_t *)sq_remfirst(&g_sigpendingaction); /* If so, then try the special list of structures reserved for * interrupt handlers */ if (!sigq) { sigq = (FAR sigq_t *)sq_remfirst(&g_sigpendingirqaction); } } /* If we were not called from an interrupt handler, then we are * free to allocate pending signal action structures if necessary. */ else { /* Try to get the pending signal action structure from the free list */ saved_state = irqsave(); sigq = (FAR sigq_t *)sq_remfirst(&g_sigpendingaction); irqrestore(saved_state); /* Check if we got one. */ if (!sigq) { /* No...Try the resource pool */ if (!sigq) { sigq = (FAR sigq_t *)kmm_malloc((sizeof (sigq_t))); } /* Check if we got an allocated message */ if (sigq) { sigq->type = SIG_ALLOC_DYN; } } } return sigq; }
static int mtdconfig_getconfig(FAR struct mtdconfig_struct_s *dev, FAR struct config_data_s *pdata) { int ret = -ENOSYS; off_t offset, bytes_to_read; struct mtdconfig_header_s hdr; /* Allocate a temp block buffer */ dev->buffer = (FAR uint8_t *)kmm_malloc(dev->blocksize); if (dev->buffer == NULL) { return -ENOMEM; } /* Get the offset of the first entry. This will also check * the format signature bytes. */ offset = mtdconfig_findfirstentry(dev, &hdr); offset = mtdconfig_findentry(dev, offset, pdata, &hdr); /* Test if the header was found. */ if (offset > 0 && (pdata->id == hdr.id && pdata->instance == hdr.instance)) { /* Entry found. Read the data */ bytes_to_read = hdr.len; if (bytes_to_read > pdata->len) { bytes_to_read = pdata->len; } /* Perform the read */ ret = mtdconfig_readbytes(dev, offset + sizeof(hdr), pdata->configdata, bytes_to_read); if (ret != OK) { /* Error reading the data */ ret = -EIO; goto errout; } ret = OK; } errout: /* Free the buffer */ kmm_free(dev->buffer); return ret; }
int usbdev_apbinitialize(struct apbridge_usb_driver *driver) { struct apbridge_alloc_s *alloc; struct apbridge_dev_s *priv; struct apbridge_driver_s *drvr; int ret; /* Allocate the structures needed */ alloc = (struct apbridge_alloc_s *) kmm_malloc(sizeof(struct apbridge_alloc_s)); if (!alloc) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_ALLOCDEVSTRUCT), 0); return -ENOMEM; } /* Convenience pointers into the allocated blob */ priv = &alloc->dev; drvr = &alloc->drvr; /* Initialize the USB driver structure */ memset(priv, 0, sizeof(struct apbridge_dev_s)); priv->driver = driver; /* Initialize the USB class driver structure */ drvr->drvr.speed = USB_SPEED_HIGH; drvr->drvr.ops = &g_driverops; drvr->dev = priv; /* Register the USB serial class driver */ ret = usbdev_register(&drvr->drvr); if (ret) { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_DEVREGISTER), (uint16_t) - ret); goto errout_with_alloc; } ret = priv->driver->init(priv); if (ret) goto errout_with_init; /* Register the single port supported by this implementation */ return OK; errout_with_init: usbdev_unregister(&drvr->drvr); errout_with_alloc: kmm_free(alloc); return ret; }
int foreach_inode(foreach_inode_t handler, FAR void *arg) { #ifdef ENUM_INODE_ALLOC FAR struct inode_path_s *info; int ret; /* Allocate the mountpoint info structure */ info = (FAR struct inode_path_s *)kmm_malloc(sizeof(struct inode_path_s)); if (!info) { return -ENOMEM; } /* Initialize the info structure */ info->handler = handler; info->arg = arg; info->path[0] = '\0'; /* Start the recursion at the root inode */ inode_semtake(); ret = foreach_inodelevel(root_inode, info); inode_semgive(); /* Free the info structure and return the result */ kmm_free(info); return ret; #else struct inode_path_s info; int ret; /* Initialize the info structure */ info.handler = handler; info.arg = arg; info.path[0] = '\0'; /* Start the recursion at the root inode */ inode_semtake(); ret = foreach_inodelevel(root_inode, &info); inode_semgive(); return ret; #endif }
FAR struct mqueue_msg_s *mq_msgalloc(void) { FAR struct mqueue_msg_s *mqmsg; irqstate_t saved_state; /* If we were called from an interrupt handler, then try to get the message * from generally available list of messages. If this fails, then try the * list of messages reserved for interrupt handlers */ if (up_interrupt_context()) { /* Try the general free list */ mqmsg = (FAR struct mqueue_msg_s *)sq_remfirst(&g_msgfree); if (!mqmsg) { /* Try the free list reserved for interrupt handlers */ mqmsg = (FAR struct mqueue_msg_s *)sq_remfirst(&g_msgfreeirq); } } /* We were not called from an interrupt handler. */ else { /* Try to get the message from the generally available free list. * Disable interrupts -- we might be called from an interrupt handler. */ saved_state = irqsave(); mqmsg = (FAR struct mqueue_msg_s *)sq_remfirst(&g_msgfree); irqrestore(saved_state); /* If we cannot a message from the free list, then we will have to allocate one. */ if (!mqmsg) { mqmsg = (FAR struct mqueue_msg_s *)kmm_malloc((sizeof (struct mqueue_msg_s))); /* Check if we got an allocated message */ ASSERT(mqmsg); mqmsg->type = MQ_ALLOC_DYN; } } return mqmsg; }
int romdisk_register(int minor, uint8_t *buffer, uint32_t nsectors, uint16_t sectsize) #endif { struct rd_struct_s *dev; char devname[16]; int ret = -ENOMEM; fvdbg("buffer: %p nsectors: %d sectsize: %d\n", buffer, nsectors, sectsize); /* Sanity check */ #ifdef CONFIG_DEBUG if (minor < 0 || minor > 255 || !buffer || !nsectors || !sectsize) { return -EINVAL; } #endif /* Allocate a ramdisk device structure */ dev = (struct rd_struct_s *)kmm_malloc(sizeof(struct rd_struct_s)); if (dev) { /* Initialize the ramdisk device structure */ dev->rd_nsectors = nsectors; /* Number of sectors on device */ dev->rd_sectsize = sectsize; /* The size of one sector */ #ifdef CONFIG_FS_WRITABLE dev->rd_writeenabled = writeenabled; /* true: can write to ram disk */ #endif dev->rd_buffer = buffer; /* RAM disk backup memory */ /* Create a ramdisk device name */ snprintf(devname, 16, "/dev/ram%d", minor); /* Inode private data is a reference to the ramdisk device structure */ ret = register_blockdriver(devname, &g_bops, 0, dev); if (ret < 0) { fdbg("register_blockdriver failed: %d\n", -ret); kmm_free(dev); } } return ret; }
static struct posix_timer_s *timer_allocate(void) { FAR struct posix_timer_s *ret; irqstate_t flags; uint8_t pt_flags; /* Try to get a preallocated timer from the free list */ #if CONFIG_PREALLOC_TIMERS > 0 flags = irqsave(); ret = (FAR struct posix_timer_s *)sq_remfirst((FAR sq_queue_t *)&g_freetimers); irqrestore(flags); /* Did we get one? */ if (ret) { pt_flags = PT_FLAGS_PREALLOCATED; } else #endif { /* Allocate a new timer from the heap */ ret = (FAR struct posix_timer_s *)kmm_malloc(sizeof(struct posix_timer_s)); pt_flags = 0; } /* If we have a timer, then put it into the allocated timer list */ if (ret) { /* Initialize the timer structure */ memset(ret, 0, sizeof(struct posix_timer_s)); ret->pt_flags = pt_flags; /* And add it to the end of the list of allocated timers */ flags = irqsave(); sq_addlast((FAR sq_entry_t *)ret, (FAR sq_queue_t *)&g_alloctimers); irqrestore(flags); } return ret; }
int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo) { size_t shdrsize; int ret; DEBUGASSERT(loadinfo->shdr == NULL); /* Verify that there are sections */ if (loadinfo->ehdr.e_shnum < 1) { serr("ERROR: No sections(?)\n"); return -EINVAL; } /* Get the total size of the section header table */ shdrsize = (size_t)loadinfo->ehdr.e_shentsize * (size_t)loadinfo->ehdr.e_shnum; if (loadinfo->ehdr.e_shoff + shdrsize > loadinfo->filelen) { serr("ERROR: Insufficent space in file for section header table\n"); return -ESPIPE; } /* Allocate memory to hold a working copy of the sector header table */ loadinfo->shdr = (FAR FAR Elf32_Shdr *)kmm_malloc(shdrsize); if (!loadinfo->shdr) { serr("ERROR: Failed to allocate the section header table. Size: %ld\n", (long)shdrsize); return -ENOMEM; } /* Read the section header table into memory */ ret = mod_read(loadinfo, (FAR uint8_t *)loadinfo->shdr, shdrsize, loadinfo->ehdr.e_shoff); if (ret < 0) { serr("ERROR: Failed to read section header table: %d\n", ret); } return ret; }
FAR struct pipe_dev_s *pipecommon_allocdev(void) { struct pipe_dev_s *dev; /* Allocate a private structure to manage the pipe */ dev = (struct pipe_dev_s *)kmm_malloc(sizeof(struct pipe_dev_s)); if (dev) { /* Initialize the private structure */ memset(dev, 0, sizeof(struct pipe_dev_s)); sem_init(&dev->d_bfsem, 0, 1); sem_init(&dev->d_rdsem, 0, 0); sem_init(&dev->d_wrsem, 0, 0); } return dev; }
int usbmsc_archinitialize(void) { uint8_t *pbuffer; int ret; pbuffer = (uint8_t *)kmm_malloc(BUFFER_SIZE); if (!pbuffer) { lowsyslog(LOG_ERR, "ERROR: Failed to allocate ramdisk of size %d\n", BUFFER_SIZE); return -ENOMEM; } /* Register a RAMDISK device to manage this RAM image */ ret = ramdisk_register(CONFIG_SYSTEM_USBMSC_DEVMINOR1, pbuffer, USBMSC_NSECTORS, USBMSC_SECTORSIZE, RDFLAG_WRENABLED | RDFLAG_FUNLINK); if (ret < 0) { syslog(LOG_ERR, "ERROR: create_ramdisk: Failed to register ramdisk at %s: %d\n", g_source, -ret); kmm_free(pbuffer); return ret; } /* Create a FAT filesystem on the ramdisk */ ret = mkfatfs(g_source, &g_fmt); if (ret < 0) { syslog(LOG_ERR, "ERROR: create_ramdisk: Failed to create FAT filesystem on ramdisk at %s\n", g_source); /* kmm_free(pbuffer); -- RAM disk is registered */ return ret; } return 0; }
int elf_allocbuffer(FAR struct elf_loadinfo_s *loadinfo) { /* Has a buffer been allocated> */ if (!loadinfo->iobuffer) { /* No.. allocate one now */ loadinfo->iobuffer = (FAR uint8_t *)kmm_malloc(CONFIG_ELF_BUFFERSIZE); if (!loadinfo->iobuffer) { bdbg("Failed to allocate an I/O buffer\n"); return -ENOMEM; } loadinfo->buflen = CONFIG_ELF_BUFFERSIZE; } return OK; }
int mtdconfig_register(FAR struct mtd_dev_s *mtd) { int ret = OK; struct mtdconfig_struct_s *dev; struct mtd_geometry_s geo; /* Device geometry */ dev = (struct mtdconfig_struct_s *)kmm_malloc(sizeof(struct mtdconfig_struct_s)); if (dev) { /* Initialize the mtdconfig device structure */ dev->mtd = mtd; sem_init(&dev->exclsem, 0, 1); /* Get the device geometry. (casting to uintptr_t first eliminates * complaints on some architectures where the sizeof long is different * from the size of a pointer). */ ret = MTD_IOCTL(mtd, MTDIOC_GEOMETRY, (unsigned long)((uintptr_t)&geo)); if (ret < 0) { fdbg("MTD ioctl(MTDIOC_GEOMETRY) failed: %d\n", ret); kmm_free(dev); goto errout; } dev->blocksize = geo.blocksize; dev->neraseblocks = geo.neraseblocks; dev->erasesize = geo.erasesize; dev->nblocks = geo.neraseblocks * geo.erasesize / geo.blocksize; (void)register_driver("/dev/config", &mtdconfig_fops, 0666, dev); } errout: return ret; }
int lm75_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, uint8_t addr) { FAR struct lm75_dev_s *priv; int ret; /* Sanity check */ DEBUGASSERT(i2c != NULL); DEBUGASSERT(addr == CONFIG_LM75_ADDR0 || addr == CONFIG_LM75_ADDR1 || addr == CONFIG_LM75_ADDR2 || addr == CONFIG_LM75_ADDR3 || addr == CONFIG_LM75_ADDR4 || addr == CONFIG_LM75_ADDR5 || addr == CONFIG_LM75_ADDR6 || addr == CONFIG_LM75_ADDR7); /* Initialize the LM-75 device structure */ priv = (FAR struct lm75_dev_s *)kmm_malloc(sizeof(struct lm75_dev_s)); if (priv == NULL) { sndbg("Failed to allocate instance\n"); return -ENOMEM; } priv->i2c = i2c; priv->addr = addr; priv->fahrenheit = false; /* Register the character driver */ ret = register_driver(devpath, &g_lm75fops, 0666, priv); if (ret < 0) { sndbg("Failed to register driver: %d\n", ret); kmm_free(priv); } return ret; }
int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) { uint32_t *stack_alloc_ptr; int ret = ERROR; size_t *adj_stack_ptr; /* Move up to next even word boundary if necessary */ size_t adj_stack_size = (stack_size + 3) & ~3; size_t adj_stack_words = adj_stack_size >> 2; /* Allocate the memory for the stack */ #if defined(CONFIG_BUILD_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP) /* Use the kernel allocator if this is a kernel thread */ if (ttype == TCB_FLAG_TTYPE_KERNEL) { stack_alloc_ptr = (uint32_t *)kmm_malloc(stack_size); } else #endif { stack_alloc_ptr = (uint32_t*)kumm_malloc(adj_stack_size); } if (stack_alloc_ptr) { /* This is the address of the last word in the allocation */ adj_stack_ptr = &stack_alloc_ptr[adj_stack_words - 1]; /* Save the values in the TCB */ tcb->adj_stack_size = adj_stack_size; tcb->stack_alloc_ptr = stack_alloc_ptr; tcb->adj_stack_ptr = (void *)((unsigned int)adj_stack_ptr & ~7); ret = OK; } return ret; }
int pca9635pw_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, uint8_t const pca9635pw_i2c_addr) { /* Sanity check */ DEBUGASSERT(i2c != NULL); /* Initialize the PCA9635PW device structure */ FAR struct pca9635pw_dev_s *priv = (FAR struct pca9635pw_dev_s *)kmm_malloc(sizeof(struct pca9635pw_dev_s)); if (priv == NULL) { dbg("Failed to allocate instance of pca9635pw_dev_s\n"); return -ENOMEM; } priv->i2c = i2c; priv->i2c_addr = pca9635pw_i2c_addr; /* Register the character driver */ int const ret = register_driver(devpath, &g_pca9635pw_fileops, 666, priv); if (ret != OK) { dbg("Failed to register driver: %d\n", ret); kmm_free(priv); return ret; } /* setup i2c frequency */ I2C_SETFREQUENCY(priv->i2c, I2C_BUS_FREQ_HZ); return OK; }