static void isp_stat_buf_insert_magic(struct ispstat *stat, struct ispstat_buffer *buf) { const u32 buf_size = IS_H3A_AF(stat) ? stat->buf_size + AF_EXTRA_DATA : stat->buf_size; isp_stat_buf_sync_magic_for_cpu(stat, buf, buf_size, DMA_FROM_DEVICE); memset(buf->virt_addr, MAGIC_NUM, MAGIC_SIZE); memset(buf->virt_addr + buf_size, MAGIC_NUM, MAGIC_SIZE); isp_stat_buf_sync_magic_for_device(stat, buf, buf_size, DMA_BIDIRECTIONAL); }
static void isp_stat_buf_insert_magic(struct ispstat *stat, struct ispstat_buffer *buf) { const u32 buf_size = IS_H3A_AF(stat) ? stat->buf_size + AF_EXTRA_DATA : stat->buf_size; isp_stat_buf_sync_magic_for_cpu(stat, buf, buf_size, DMA_FROM_DEVICE); /* * Inserting MAGIC_NUM at the beginning and end of the buffer. * buf->buf_size is set only after the buffer is queued. For now the * right buf_size for the current configuration is pointed by * stat->buf_size. */ memset(buf->virt_addr, MAGIC_NUM, MAGIC_SIZE); memset(buf->virt_addr + buf_size, MAGIC_NUM, MAGIC_SIZE); isp_stat_buf_sync_magic_for_device(stat, buf, buf_size, DMA_BIDIRECTIONAL); }
static int isp_stat_buf_check_magic(struct ispstat *stat, struct ispstat_buffer *buf) { const u32 buf_size = IS_H3A_AF(stat) ? buf->buf_size + AF_EXTRA_DATA : buf->buf_size; u8 *w; u8 *end; int ret = -EINVAL; isp_stat_buf_sync_magic_for_cpu(stat, buf, buf_size, DMA_FROM_DEVICE); /* Checking initial magic numbers. They shouldn't be here anymore. */ for (w = buf->virt_addr, end = w + MAGIC_SIZE; w < end; w++) if (likely(*w != MAGIC_NUM)) ret = 0; if (ret) { dev_dbg(stat->isp->dev, "%s: beginning magic check does not match.\n", stat->subdev.name); return ret; } /* Checking magic numbers at the end. They must be still here. */ for (w = buf->virt_addr + buf_size, end = w + MAGIC_SIZE; w < end; w++) { if (unlikely(*w != MAGIC_NUM)) { dev_dbg(stat->isp->dev, "%s: ending magic check does not match.\n", stat->subdev.name); return -EINVAL; } } isp_stat_buf_sync_magic_for_device(stat, buf, buf_size, DMA_FROM_DEVICE); return 0; }
static int isp_stat_buf_check_magic(struct ispstat *stat, struct ispstat_buffer *buf) { const u32 buf_size = IS_H3A_AF(stat) ? buf->buf_size + AF_EXTRA_DATA : buf->buf_size; u8 *w; u8 *end; int ret = -EINVAL; isp_stat_buf_sync_magic_for_cpu(stat, buf, buf_size, DMA_FROM_DEVICE); for (w = buf->virt_addr, end = w + MAGIC_SIZE; w < end; w++) if (likely(*w != MAGIC_NUM)) ret = 0; if (ret) { dev_dbg(stat->isp->dev, "%s: beginning magic check does not " "match.\n", stat->subdev.name); return ret; } for (w = buf->virt_addr + buf_size, end = w + MAGIC_SIZE; w < end; w++) { if (unlikely(*w != MAGIC_NUM)) { dev_dbg(stat->isp->dev, "%s: endding magic check does " "not match.\n", stat->subdev.name); return -EINVAL; } } isp_stat_buf_sync_magic_for_device(stat, buf, buf_size, DMA_FROM_DEVICE); return 0; }