Re: [RFC PATCH 07/11] coresight: add CoreSight ETM driver

From: Daniel Thompson
Date: Tue Jun 03 2014 - 13:05:13 EST


On 03/06/14 17:37, Mathieu Poirier wrote:
>>> +static ssize_t debugfs_status_read(struct file *file, char __user *user_buf,
>>> + size_t count, loff_t *ppos)
>>> +{
>>> + ssize_t ret;
>>> + uint32_t val;
>>> + unsigned long flags;
>>> + char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
>>> + struct etm_drvdata *drvdata = file->private_data;
>>> +
>>> + if (!buf)
>>> + return -ENOMEM;
>>> +
>>> + ret = clk_prepare_enable(drvdata->clk);
>>> + if (ret)
>>> + goto out;
>>> +
>>> + spin_lock_irqsave(&drvdata->spinlock, flags);
>>> +
>>> + ETM_UNLOCK(drvdata);
>>> + val = etm_readl(drvdata, ETMCCR);
>>> + ret += sprintf(buf, "ETMCCR: 0x%08x\n", val);
>>> + val = etm_readl(drvdata, ETMCCER);
>>> + ret += sprintf(buf + ret, "ETMCCER: 0x%08x\n", val);
>>> + val = etm_readl(drvdata, ETMSCR);
>>> + ret += sprintf(buf + ret, "ETMSCR: 0x%08x\n", val);
>>> + val = etm_readl(drvdata, ETMIDR);
>>> + ret += sprintf(buf + ret, "ETMIDR: 0x%08x\n", val);
>>> + val = etm_readl(drvdata, ETMCR);
>>> + ret += sprintf(buf + ret, "ETMCR: 0x%08x\n", val);
>>> + val = etm_readl(drvdata, ETMTEEVR);
>>> + ret += sprintf(buf + ret, "Enable event: 0x%08x\n", val);
>>> + val = etm_readl(drvdata, ETMTSSCR);
>>> + ret += sprintf(buf + ret, "Enable start/stop: 0x%08x\n", val);
>>> + ret += sprintf(buf + ret,
>>> + "Enable control: CR1 0x%08x CR2 0x%08x\n",
>>> + etm_readl(drvdata, ETMTECR1),
>>> + etm_readl(drvdata, ETMTECR2));
>>> +
>>> + ETM_LOCK(drvdata);
>>> +
>>> + spin_unlock_irqrestore(&drvdata->spinlock, flags);
>>> + clk_disable_unprepare(drvdata->clk);
>>> +
>>> + ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
>>> +out:
>>> + kfree(buf);
>>> + return ret;
>>> +}
>>
>> Really not sure whether this should be in the read method. If we don't
>> read the file in one go the spin_lock() we'll not get a cohesive set of
>> registers.
>
> I get your point but since there is a possibility (even very remove)
> that any of these registers can be changed between the two read
> operations, the only reasonable solution I see is to return an error
> if (ret > size). What your opinion on that?

I'd prefer that we simply copy the approach used by simple_attr_read().


Daniel.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/