/*------------------------------------------------------------------------------ * Context: softirq */ int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type, u8 index, u16 windex, int offset, int len) { struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; struct oz_pd *pd = usb_ctx->pd; struct oz_elt *elt; struct oz_get_desc_req *body; struct oz_elt_buf *eb = &pd->elt_buff; struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); if (len > 200) len = 200; if (ei == 0) return -1; ei->callback = oz_usb_setup_elt_completion_callback; ei->context = req_id; elt = (struct oz_elt *)ei->data; elt->length = sizeof(struct oz_get_desc_req); body = (struct oz_get_desc_req *)(elt+1); body->type = OZ_GET_DESC_REQ; body->req_id = req_id; put_unaligned(cpu_to_le16(offset), &body->offset); put_unaligned(cpu_to_le16(len), &body->size); body->req_type = req_type; body->desc_type = desc_type; body->w_index = windex; body->index = index; return oz_usb_submit_elt(eb, ei, usb_ctx, 0, 0); }
/* prepare ordinary wander record block (fill all service fields) */ static void format_wander_record(struct commit_handle *ch, jnode *node, __u32 serial) { struct wander_record_header *LRH; jnode *next; assert("zam-464", node != NULL); LRH = (struct wander_record_header *)jdata(node); next = list_entry(node->capture_link.next, jnode, capture_link); if (&ch->tx_list == &next->capture_link) next = list_entry(ch->tx_list.next, jnode, capture_link); assert("zam-465", LRH != NULL); assert("zam-463", ch->super->s_blocksize > sizeof(struct wander_record_header)); memset(jdata(node), 0, (size_t) ch->super->s_blocksize); memcpy(jdata(node), WANDER_RECORD_MAGIC, WANDER_RECORD_MAGIC_SIZE); put_unaligned(cpu_to_le32(ch->tx_size), &LRH->total); put_unaligned(cpu_to_le32(serial), &LRH->serial); put_unaligned(cpu_to_le64(*jnode_get_block(next)), &LRH->next_block); }
void netpoll_send_udp(struct netpoll *np, const char *msg, int len) { int total_len, eth_len, ip_len, udp_len; struct sk_buff *skb; struct udphdr *udph; struct iphdr *iph; struct ethhdr *eth; udp_len = len + sizeof(*udph); ip_len = eth_len = udp_len + sizeof(*iph); total_len = eth_len + ETH_HLEN + NET_IP_ALIGN; skb = find_skb(np, total_len, total_len - len); if (!skb) return; skb_copy_to_linear_data(skb, msg, len); skb->len += len; skb_push(skb, sizeof(*udph)); skb_reset_transport_header(skb); udph = udp_hdr(skb); udph->source = htons(np->local_port); udph->dest = htons(np->remote_port); udph->len = htons(udp_len); udph->check = 0; udph->check = csum_tcpudp_magic(htonl(np->local_ip), htonl(np->remote_ip), udp_len, IPPROTO_UDP, csum_partial((unsigned char *)udph, udp_len, 0)); if (udph->check == 0) udph->check = CSUM_MANGLED_0; skb_push(skb, sizeof(*iph)); skb_reset_network_header(skb); iph = ip_hdr(skb); /* iph->version = 4; iph->ihl = 5; */ put_unaligned(0x45, (unsigned char *)iph); iph->tos = 0; put_unaligned(htons(ip_len), &(iph->tot_len)); iph->id = 0; iph->frag_off = 0; iph->ttl = 64; iph->protocol = IPPROTO_UDP; iph->check = 0; put_unaligned(htonl(np->local_ip), &(iph->saddr)); put_unaligned(htonl(np->remote_ip), &(iph->daddr)); iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); eth = (struct ethhdr *) skb_push(skb, ETH_HLEN); skb_reset_mac_header(skb); skb->protocol = eth->h_proto = htons(ETH_P_IP); memcpy(eth->h_source, np->local_mac, 6); memcpy(eth->h_dest, np->remote_mac, 6); skb->dev = np->dev; netpoll_send_skb(np, skb); }
/* fill journal footer block data */ static void format_journal_footer(struct commit_handle *ch) { struct reiser4_super_info_data *sbinfo; struct journal_footer *footer; jnode *tx_head; sbinfo = get_super_private(ch->super); tx_head = list_entry(ch->tx_list.next, jnode, capture_link); assert("zam-493", sbinfo != NULL); assert("zam-494", sbinfo->journal_header != NULL); check_me("zam-691", jload(sbinfo->journal_footer) == 0); footer = (struct journal_footer *)jdata(sbinfo->journal_footer); assert("zam-495", footer != NULL); put_unaligned(cpu_to_le64(*jnode_get_block(tx_head)), &footer->last_flushed_tx); put_unaligned(cpu_to_le64(ch->free_blocks), &footer->free_blocks); put_unaligned(cpu_to_le64(ch->nr_files), &footer->nr_files); put_unaligned(cpu_to_le64(ch->next_oid), &footer->next_oid); jrelse(sbinfo->journal_footer); }
/* * Context: tasklet */ static int oz_usb_vendor_class_req(void *hpd, u8 req_id, u8 req_type, u8 request, __le16 value, __le16 index, const u8 *data, int data_len) { struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; struct oz_pd *pd = usb_ctx->pd; struct oz_elt *elt; struct oz_elt_buf *eb = &pd->elt_buff; struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); struct oz_vendor_class_req *body; if (ei == NULL) return -1; elt = (struct oz_elt *)ei->data; elt->length = sizeof(struct oz_vendor_class_req) - 1 + data_len; body = (struct oz_vendor_class_req *)(elt+1); body->type = OZ_VENDOR_CLASS_REQ; body->req_id = req_id; body->req_type = req_type; body->request = request; put_unaligned(value, &body->value); put_unaligned(index, &body->index); if (data_len) memcpy(body->data, data, data_len); return oz_usb_submit_elt(eb, ei, usb_ctx, 0, 0); }
static void idefloppy_create_rw_cmd(ide_drive_t *drive, struct ide_atapi_pc *pc, struct request *rq, unsigned long sector) { struct ide_disk_obj *floppy = drive->driver_data; int block = sector / floppy->bs_factor; int blocks = rq->nr_sectors / floppy->bs_factor; int cmd = rq_data_dir(rq); ide_debug_log(IDE_DBG_FUNC, "block: %d, blocks: %d", block, blocks); ide_init_pc(pc); pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10; put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]); put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]); memcpy(rq->cmd, pc->c, 12); pc->rq = rq; if (rq->cmd_flags & REQ_RW) pc->flags |= PC_FLAG_WRITING; pc->buf = NULL; pc->req_xfer = pc->buf_size = blocks * floppy->block_size; pc->flags |= PC_FLAG_DMA_OK; }
/* * Context: softirq */ int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type, u8 index, u16 windex, int offset, int len) { struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; struct oz_pd *pd = usb_ctx->pd; struct oz_elt *elt; struct oz_get_desc_req *body; struct oz_elt_buf *eb = &pd->elt_buff; struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); oz_dbg(ON, " req_type = 0x%x\n", req_type); oz_dbg(ON, " desc_type = 0x%x\n", desc_type); oz_dbg(ON, " index = 0x%x\n", index); oz_dbg(ON, " windex = 0x%x\n", windex); oz_dbg(ON, " offset = 0x%x\n", offset); oz_dbg(ON, " len = 0x%x\n", len); if (len > 200) len = 200; if (ei == NULL) return -1; elt = (struct oz_elt *)ei->data; elt->length = sizeof(struct oz_get_desc_req); body = (struct oz_get_desc_req *)(elt+1); body->type = OZ_GET_DESC_REQ; body->req_id = req_id; put_unaligned(cpu_to_le16(offset), &body->offset); put_unaligned(cpu_to_le16(len), &body->size); body->req_type = req_type; body->desc_type = desc_type; body->w_index = windex; body->index = index; return oz_usb_submit_elt(eb, ei, usb_ctx, 0, 0); }
static bool alx_read_macaddr(struct alx_hw *hw, u8 *addr) { u32 mac0, mac1; mac0 = alx_read_mem32(hw, ALX_STAD0); mac1 = alx_read_mem32(hw, ALX_STAD1); /* addr should be big-endian */ put_unaligned(cpu_to_be32(mac0), (__be32 *)(addr + 2)); put_unaligned(cpu_to_be16(mac1), (__be16 *)addr); return is_valid_ether_addr(addr); }
static int hcd_alloc_coherent(struct usb_bus *bus, gfp_t mem_flags, dma_addr_t *dma_handle, void **vaddr_handle, size_t size, enum dma_data_direction dir) { unsigned char *vaddr; vaddr = hcd_buffer_alloc(bus, size + sizeof(vaddr), mem_flags, dma_handle); if (!vaddr) return -ENOMEM; /* * Store the virtual address of the buffer at the end * of the allocated dma buffer. The size of the buffer * may be uneven so use unaligned functions instead * of just rounding up. It makes sense to optimize for * memory footprint over access speed since the amount * of memory available for dma may be limited. */ put_unaligned((unsigned long)*vaddr_handle, (unsigned long *)(vaddr + size)); if (dir == DMA_TO_DEVICE) memcpy(vaddr, *vaddr_handle, size); *vaddr_handle = vaddr; return 0; }
/* add one wandered map entry to formatted wander record */ static void store_entry(jnode * node, int index, const reiser4_block_nr * a, const reiser4_block_nr * b) { char *data; struct wander_entry *pairs; data = jdata(node); assert("zam-451", data != NULL); pairs = (struct wander_entry *)(data + sizeof(struct wander_record_header)); put_unaligned(cpu_to_le64(*a), &pairs[index].original); put_unaligned(cpu_to_le64(*b), &pairs[index].wandered); }
/* * Send an acknowledgement message to userspace * * Use 0 for success, EFOO otherwise. * Note: this is the negative of conventional kernel error * values because it's not being returned via syscall return * mechanisms. */ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack) { struct cn_msg *msg; struct proc_event *ev; __u8 buffer[CN_PROC_MSG_SIZE]; struct timespec ts; if (atomic_read(&proc_event_num_listeners) < 1) return; msg = (struct cn_msg*)buffer; ev = (struct proc_event*)msg->data; memset(&ev->event_data, 0, sizeof(ev->event_data)); msg->seq = rcvd_seq; ktime_get_ts(&ts); /* get high res monotonic timestamp */ put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); ev->cpu = -1; ev->what = PROC_EVENT_NONE; ev->event_data.ack.err = err; memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack = rcvd_ack + 1; msg->len = sizeof(*ev); msg->flags = 0; /* not used */ cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); }
static void read_data_from_flash_mem(uint8_t *buf, int len) { int i; uint32_t *buf32; /* transfer the data from the flash */ buf32 = (uint32_t *)buf; /* * Let's take care of unaligned access although it rarely happens. * Avoid put_unaligned() for the normal use cases since it leads to * a bit performance regression. */ if ((unsigned long)buf32 % 4) { for (i = 0; i < len / 4; i++) put_unaligned(readl(denali_flash_mem + INDEX_DATA_REG), buf32++); } else { for (i = 0; i < len / 4; i++) *buf32++ = readl(denali_flash_mem + INDEX_DATA_REG); } if (len % 4) { u32 tmp; tmp = cpu_to_le32(readl(denali_flash_mem + INDEX_DATA_REG)); buf = (uint8_t *)buf32; for (i = 0; i < len % 4; i++) { *buf++ = tmp; tmp >>= 8; } }
void proc_fork_connector(struct task_struct *task) { struct cn_msg *msg; struct proc_event *ev; __u8 buffer[CN_PROC_MSG_SIZE]; struct timespec ts; struct task_struct *parent; if (atomic_read(&proc_event_num_listeners) < 1) return; msg = (struct cn_msg*)buffer; ev = (struct proc_event*)msg->data; get_seq(&msg->seq, &ev->cpu); ktime_get_ts(&ts); /* get high res monotonic timestamp */ put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); ev->what = PROC_EVENT_FORK; rcu_read_lock(); parent = rcu_dereference(task->real_parent); ev->event_data.fork.parent_pid = parent->pid; ev->event_data.fork.parent_tgid = parent->tgid; rcu_read_unlock(); ev->event_data.fork.child_pid = task->pid; ev->event_data.fork.child_tgid = task->tgid; memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack = 0; /* not used */ msg->len = sizeof(*ev); /* If cn_netlink_send() failed, the data is not sent */ cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); }
void proc_ptrace_connector(struct task_struct *task, int ptrace_id) { struct cn_msg *msg; struct proc_event *ev; struct timespec ts; __u8 buffer[CN_PROC_MSG_SIZE]; if (atomic_read(&proc_event_num_listeners) < 1) return; msg = (struct cn_msg *)buffer; ev = (struct proc_event *)msg->data; get_seq(&msg->seq, &ev->cpu); ktime_get_ts(&ts); /* get high res monotonic timestamp */ put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); ev->what = PROC_EVENT_PTRACE; ev->event_data.ptrace.process_pid = task->pid; ev->event_data.ptrace.process_tgid = task->tgid; if (ptrace_id == PTRACE_ATTACH) { ev->event_data.ptrace.tracer_pid = current->pid; ev->event_data.ptrace.tracer_tgid = current->tgid; } else if (ptrace_id == PTRACE_DETACH) { ev->event_data.ptrace.tracer_pid = 0; ev->event_data.ptrace.tracer_tgid = 0; } else return; memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack = 0; /* not used */ msg->len = sizeof(*ev); cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); }
void proc_exit_connector(struct task_struct *task) { struct cn_msg *msg; struct proc_event *ev; __u8 buffer[CN_PROC_MSG_SIZE]; struct timespec ts; if (atomic_read(&proc_event_num_listeners) < 1) return; msg = (struct cn_msg*)buffer; ev = (struct proc_event*)msg->data; get_seq(&msg->seq, &ev->cpu); ktime_get_ts(&ts); /* get high res monotonic timestamp */ put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); ev->what = PROC_EVENT_EXIT; ev->event_data.exit.process_pid = task->pid; ev->event_data.exit.process_tgid = task->tgid; ev->event_data.exit.exit_code = task->exit_code; ev->event_data.exit.exit_signal = task->exit_signal; memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack = 0; /* not used */ msg->len = sizeof(*ev); cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); }
static int uniphier_sd_pio_read_one_block(struct udevice *dev, u32 **pbuf, uint blocksize) { struct uniphier_sd_priv *priv = dev_get_priv(dev); int i, ret; /* wait until the buffer is filled with data */ ret = uniphier_sd_wait_for_irq(dev, UNIPHIER_SD_INFO2, UNIPHIER_SD_INFO2_BRE); if (ret) return ret; /* * Clear the status flag _before_ read the buffer out because * UNIPHIER_SD_INFO2_BRE is edge-triggered, not level-triggered. */ writel(0, priv->regbase + UNIPHIER_SD_INFO2); if (likely(IS_ALIGNED((unsigned long)*pbuf, 4))) { for (i = 0; i < blocksize / 4; i++) *(*pbuf)++ = readl(priv->regbase + UNIPHIER_SD_BUF); } else { for (i = 0; i < blocksize / 4; i++) put_unaligned(readl(priv->regbase + UNIPHIER_SD_BUF), (*pbuf)++); } return 0; }
/* paste body of @entry into item */ static int paste_entry(const coord_t * coord /* coord of item */ , struct cde_entry * entry /* new entry */ , int pos /* position to insert */ , reiser4_dir_entry_desc * dir_entry /* parameters for * new entry */ ) { cde_unit_header *header; directory_entry_format *dent; const char *name; int len; header = header_at(coord, pos); dent = entry_at(coord, pos); build_de_id_by_key(&dir_entry->key, &header->hash); build_inode_key_id(entry->obj, &dent->id); /* AUDIT unsafe strcpy() operation! It should be replaced with much less CPU hungry memcpy( ( char * ) dent -> name, entry -> name -> name , entry -> name -> len ); Also a more major thing is that there should be a way to figure out amount of space in dent -> name and be able to check that we are not going to overwrite more than we supposed to */ name = entry->name->name; len = entry->name->len; if (is_longname(name, len)) { strcpy((unsigned char *)dent->name, name); put_unaligned(0, &dent->name[len]); } return 0; }
void proc_exec_connector(struct task_struct *task) { struct cn_msg *msg; struct proc_event *ev; struct timespec ts; __u8 buffer[CN_PROC_MSG_SIZE]; const struct cred *cred; if (atomic_read(&proc_event_num_listeners) < 1) return; msg = (struct cn_msg*)buffer; ev = (struct proc_event*)msg->data; get_seq(&msg->seq, &ev->cpu); ktime_get_ts(&ts); /* get high res monotonic timestamp */ put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); ev->what = PROC_EVENT_EXEC; ev->event_data.exec.process_pid = task->pid; ev->event_data.exec.process_tgid = task->tgid; rcu_read_lock(); cred = __task_cred(task); ev->event_data.exec.process_euid = cred->euid; ev->event_data.exec.process_egid = cred->egid; rcu_read_unlock(); proc_get_exe(task, ev->event_data.exec.exe); memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack = 0; /* not used */ msg->len = sizeof(*ev); cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); }
static struct sk_buff * net1080_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) { struct sk_buff *skb2; struct nc_header *header = NULL; struct nc_trailer *trailer = NULL; int padlen = sizeof (struct nc_trailer); int len = skb->len; if (!((len + padlen + sizeof (struct nc_header)) & 0x01)) padlen++; if (!skb_cloned(skb)) { int headroom = skb_headroom(skb); int tailroom = skb_tailroom(skb); if (padlen <= tailroom && sizeof(struct nc_header) <= headroom) /* There's enough head and tail room */ goto encapsulate; if ((sizeof (struct nc_header) + padlen) < (headroom + tailroom)) { /* There's enough total room, so just readjust */ skb->data = memmove(skb->head + sizeof (struct nc_header), skb->data, skb->len); skb_set_tail_pointer(skb, len); goto encapsulate; } } /* Create a new skb to use with the correct size */ skb2 = skb_copy_expand(skb, sizeof (struct nc_header), padlen, flags); dev_kfree_skb_any(skb); if (!skb2) return skb2; skb = skb2; encapsulate: /* header first */ header = (struct nc_header *) skb_push(skb, sizeof *header); header->hdr_len = cpu_to_le16(sizeof (*header)); header->packet_len = cpu_to_le16(len); header->packet_id = cpu_to_le16((u16)dev->xid++); /* maybe pad; then trailer */ if (!((skb->len + sizeof *trailer) & 0x01)) *skb_put(skb, 1) = PAD_BYTE; trailer = (struct nc_trailer *) skb_put(skb, sizeof *trailer); put_unaligned(header->packet_id, &trailer->packet_id); #if 0 netdev_dbg(dev->net, "frame >tx h %d p %d id %d\n", header->hdr_len, header->packet_len, header->packet_id); #endif return skb; }
static void nft_byteorder_eval(const struct nft_expr *expr, struct nft_regs *regs, const struct nft_pktinfo *pkt) { const struct nft_byteorder *priv = nft_expr_priv(expr); u32 *src = ®s->data[priv->sreg]; u32 *dst = ®s->data[priv->dreg]; union { u32 u32; u16 u16; } *s, *d; unsigned int i; s = (void *)src; d = (void *)dst; switch (priv->size) { case 8: { u64 src64; switch (priv->op) { case NFT_BYTEORDER_NTOH: for (i = 0; i < priv->len / 8; i++) { src64 = get_unaligned((u64 *)&src[i]); put_unaligned_be64(src64, &dst[i]); } break; case NFT_BYTEORDER_HTON: for (i = 0; i < priv->len / 8; i++) { src64 = get_unaligned_be64(&src[i]); put_unaligned(src64, (u64 *)&dst[i]); } break; } break; } case 4: switch (priv->op) { case NFT_BYTEORDER_NTOH: for (i = 0; i < priv->len / 4; i++) d[i].u32 = ntohl((__force __be32)s[i].u32); break; case NFT_BYTEORDER_HTON: for (i = 0; i < priv->len / 4; i++) d[i].u32 = (__force __u32)htonl(s[i].u32); break; } break; case 2: switch (priv->op) { case NFT_BYTEORDER_NTOH: for (i = 0; i < priv->len / 2; i++) d[i].u16 = ntohs((__force __be16)s[i].u16); break; case NFT_BYTEORDER_HTON: for (i = 0; i < priv->len / 2; i++) d[i].u16 = (__force __u16)htons(s[i].u16); break; } break; } }
int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name) { unsigned short usb_pid; usb_pid = TORADEX_USB_PRODUCT_NUM_OFFSET + tdx_hw_tag.prodid; put_unaligned(usb_pid, &dev->idProduct); return 0; }
/* expand @coord as to accommodate for insertion of @no new entries starting from @pos, with total bodies size @size. */ static int expand_item(const coord_t * coord /* coord of item */ , int pos /* unit position */ , int no /* number of new * units*/ , int size /* total size of new units' data */ , unsigned int data_size /* free space already reserved * in the item for insertion */ ) { int entries; cde_unit_header *header; char *dent; int i; assert("nikita-1310", coord != NULL); assert("nikita-1311", pos >= 0); assert("nikita-1312", no > 0); assert("nikita-1313", data_size >= no * sizeof(directory_entry_format)); assert("nikita-1343", item_length_by_coord(coord) >= (int)(size + data_size + no * sizeof *header)); entries = units(coord); if (pos == entries) dent = address(coord, size); else dent = (char *)entry_at(coord, pos); /* place where new header will be in */ header = header_at(coord, pos); /* free space for new entry headers */ memmove(header + no, header, (unsigned)(address(coord, size) - (char *)header)); /* if adding to the end initialise first new header */ if (pos == entries) { set_offset(coord, pos, (unsigned)size); } /* adjust entry pointer and size */ dent = dent + no * sizeof *header; size += no * sizeof *header; /* free space for new entries */ memmove(dent + data_size, dent, (unsigned)(address(coord, size) - dent)); /* increase counter */ entries += no; put_unaligned(cpu_to_le16((__u16) entries), &formatted_at(coord)->num_of_entries); /* [ 0 ... pos ] entries were shifted by no * ( sizeof *header ) bytes. */ for (i = 0; i <= pos; ++i) adj_offset(coord, i, no * sizeof *header); /* [ pos + no ... +\infty ) entries were shifted by ( no * sizeof *header + data_size ) bytes */ for (i = pos + no; i < entries; ++i) adj_offset(coord, i, no * sizeof *header + data_size); return 0; }
static void send_netdump_msg(struct netpoll *np, const char *msg, unsigned int msg_len, reply_t *reply) { /* max len should be 1024 + HEADER_LEN */ static unsigned char netpoll_msg[MAX_MSG_LEN + 1]; if (msg_len + HEADER_LEN > MAX_MSG_LEN + 1) { printk("CODER ERROR!!! msg_len %ud too big for send msg\n", msg_len); for (;;) local_irq_disable(); /* NOTREACHED */ } netpoll_msg[0] = effective_version; put_unaligned(htonl(reply->nr), (u32 *) (&netpoll_msg[1])); put_unaligned(htonl(reply->code), (u32 *) (&netpoll_msg[5])); put_unaligned(htonl(reply->info), (u32 *) (&netpoll_msg[9])); memcpy(&netpoll_msg[HEADER_LEN], msg, msg_len); netpoll_send_udp(np, netpoll_msg, HEADER_LEN + msg_len); }
static int crypt_iv_benbi_gen(struct crypt_config *cc, u8 *iv, struct dm_crypt_request *dmreq) { __be64 val; memset(iv, 0, cc->iv_size - sizeof(u64)); /* rest is cleared below */ val = cpu_to_be64(((u64)dmreq->iv_sector << cc->iv_gen_private.benbi.shift) + 1); put_unaligned(val, (__be64 *)(iv + cc->iv_size - sizeof(u64))); return 0; }
static void adj_offset(const coord_t * coord /* coord of item */ , int idx /* index of unit */ , int delta /* offset change */ ) { d16 *doffset; __u16 offset; doffset = &header_at(coord, idx)->offset; offset = le16_to_cpu(get_unaligned(doffset)); offset += delta; put_unaligned(cpu_to_le16((__u16) offset), doffset); }
/* Fill first wander record (tx head) in accordance with supplied given data */ static void format_tx_head(struct commit_handle *ch) { jnode *tx_head; jnode *next; struct tx_header *header; tx_head = list_entry(ch->tx_list.next, jnode, capture_link); assert("zam-692", &ch->tx_list != &tx_head->capture_link); next = list_entry(tx_head->capture_link.next, jnode, capture_link); if (&ch->tx_list == &next->capture_link) next = tx_head; header = (struct tx_header *)jdata(tx_head); assert("zam-460", header != NULL); assert("zam-462", ch->super->s_blocksize >= sizeof(struct tx_header)); memset(jdata(tx_head), 0, (size_t) ch->super->s_blocksize); memcpy(jdata(tx_head), TX_HEADER_MAGIC, TX_HEADER_MAGIC_SIZE); put_unaligned(cpu_to_le32(ch->tx_size), &header->total); put_unaligned(cpu_to_le64(get_super_private(ch->super)->last_committed_tx), &header->prev_tx); put_unaligned(cpu_to_le64(*jnode_get_block(next)), &header->next_block); put_unaligned(cpu_to_le64(ch->free_blocks), &header->free_blocks); put_unaligned(cpu_to_le64(ch->nr_files), &header->nr_files); put_unaligned(cpu_to_le64(ch->next_oid), &header->next_oid); }
/* * si470x_set_register - write register */ static int si470x_set_register(struct si470x_device *radio, int regnr) { unsigned char buf[REGISTER_REPORT_SIZE]; int retval; buf[0] = REGISTER_REPORT(regnr); put_unaligned(cpu_to_be16(radio->registers[regnr]), (unsigned short *) &buf[1]); retval = si470x_set_report(radio, (void *) &buf, sizeof(buf)); return (retval < 0) ? -EINVAL : 0; }
/* Perform WEP encryption using given key. data buffer must have tailroom * for 4-byte ICV. data_len must not include this ICV. Note: this function * does _not_ add IV. data = RC4(data | CRC32(data)) */ void ieee80211_wep_encrypt_data(struct crypto_cipher *tfm, u8 *rc4key, size_t klen, u8 *data, size_t data_len) { __le32 icv; int i; icv = cpu_to_le32(~crc32_le(~0, data, data_len)); put_unaligned(icv, (__le32 *)(data + data_len)); crypto_cipher_setkey(tfm, rc4key, klen); for (i = 0; i < data_len + IEEE80211_WEP_ICV_LEN; i++) crypto_cipher_encrypt_one(tfm, data + i, data + i); }
/* * Insert the address ADDR into the symbol reference at RP; * RELVAL is the raw relocation-table entry from which RP is derived */ void bfin_put_addr_at_rp(unsigned long *ptr, unsigned long addr, unsigned long relval) { unsigned short *usptr = (unsigned short *)ptr; int type = (relval >> 26) & 7; switch (type) { case FLAT_BFIN_RELOC_TYPE_16_BIT: put_unaligned(addr, usptr); pr_debug("new value %x at %p", get_unaligned(usptr), usptr); break; case FLAT_BFIN_RELOC_TYPE_16H_BIT: put_unaligned(addr >> 16, usptr); pr_debug("new value %x", get_unaligned(usptr)); break; case FLAT_BFIN_RELOC_TYPE_32_BIT: put_unaligned(addr, ptr); pr_debug("new ptr =%lx", get_unaligned(ptr)); break; } }
void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr), unsigned long r_type, void *orig_loc, unsigned long UNUSED(address), unsigned long relocation) { uint32_t *location = orig_loc; uint32_t value; switch (r_type) { case R_SH_DIR32: value = get_unaligned(location); value += relocation; put_unaligned(value, location); break; case R_SH_REL32: relocation = (relocation - (uint32_t)location); value = get_unaligned(location); value += relocation; put_unaligned(value, location); break; default: die("Unknown rela relocation: %lu\n", r_type); break; } }