diff mbox series

[08/13] ASoC: Intel: catpt: Simple sysfs attributes

Message ID 20200807110649.17114-9-cezary.rojewski@intel.com (mailing list archive)
State New, archived
Headers show
Series ASoC: Intel: Catpt - Lynx and Wildcat point | expand

Commit Message

Cezary Rojewski Aug. 7, 2020, 11:06 a.m. UTC
Add sysfs entries for displaying version of FW currently in use as well
as binary dump of entire version info, including build and log providers
hashes.

Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
---
 sound/soc/intel/catpt/fs.c | 79 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100644 sound/soc/intel/catpt/fs.c

Comments

Mark Brown Aug. 7, 2020, 3 p.m. UTC | #1
On Fri, Aug 07, 2020 at 01:06:44PM +0200, Cezary Rojewski wrote:

> +// SPDX-License-Identifier: GPL-2.0-pcm

I'm not able to find any references to what license this is - it's not
in https://spdx.org/licenses/ for example.

> +	struct catpt_fw_version version;
> +	int ret;
> +
> +	pm_runtime_get_sync(cdev->dev);
> +
> +	ret = catpt_ipc_get_fw_version(cdev, &version);
> +
> +	pm_runtime_mark_last_busy(cdev->dev);
> +	pm_runtime_put_autosuspend(cdev->dev);
> +
> +	if (ret)
> +		return CATPT_IPC_ERROR(ret);
> +
> +	memcpy(buf, &version, count);

This will copy count bytes from version regardless of the size of
version - this allows userspace to read the stack and won't truncate the
count to the size of the data read.
Cezary Rojewski Aug. 10, 2020, 7:17 a.m. UTC | #2
On 2020-08-07 5:00 PM, Mark Brown wrote:
> On Fri, Aug 07, 2020 at 01:06:44PM +0200, Cezary Rojewski wrote:
> 
>> +// SPDX-License-Identifier: GPL-2.0-pcm
> 
> I'm not able to find any references to what license this is - it's not
> in https://spdx.org/licenses/ for example.
> 

Indeed. this is a mistake. Will fix in v2.

>> +	struct catpt_fw_version version;
>> +	int ret;
>> +
>> +	pm_runtime_get_sync(cdev->dev);
>> +
>> +	ret = catpt_ipc_get_fw_version(cdev, &version);
>> +
>> +	pm_runtime_mark_last_busy(cdev->dev);
>> +	pm_runtime_put_autosuspend(cdev->dev);
>> +
>> +	if (ret)
>> +		return CATPT_IPC_ERROR(ret);
>> +
>> +	memcpy(buf, &version, count);
> 
> This will copy count bytes from version regardless of the size of
> version - this allows userspace to read the stack and won't truncate the
> count to the size of the data read.
> 

Good catch Mark. Ack.
diff mbox series

Patch

diff --git a/sound/soc/intel/catpt/fs.c b/sound/soc/intel/catpt/fs.c
new file mode 100644
index 000000000000..5102641b57f1
--- /dev/null
+++ b/sound/soc/intel/catpt/fs.c
@@ -0,0 +1,79 @@ 
+// SPDX-License-Identifier: GPL-2.0-pcm
+//
+// Copyright(c) 2020 Intel Corporation. All rights reserved.
+//
+// Author: Cezary Rojewski <cezary.rojewski@intel.com>
+//
+
+#include <linux/pm_runtime.h>
+#include "core.h"
+
+static ssize_t fw_version_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct catpt_dev *cdev = dev_get_drvdata(dev);
+	struct catpt_fw_version version;
+	int ret;
+
+	pm_runtime_get_sync(cdev->dev);
+
+	ret = catpt_ipc_get_fw_version(cdev, &version);
+
+	pm_runtime_mark_last_busy(cdev->dev);
+	pm_runtime_put_autosuspend(cdev->dev);
+
+	if (ret)
+		return CATPT_IPC_ERROR(ret);
+
+	return sprintf(buf, "%d.%d.%d.%d\n", version.type, version.major,
+		       version.minor, version.build);
+}
+
+static DEVICE_ATTR_RO(fw_version);
+
+static ssize_t fw_build_read(struct file *filp, struct kobject *kobj,
+			     struct bin_attribute *bin_attr, char *buf,
+			     loff_t off, size_t count)
+{
+	struct catpt_dev *cdev = dev_get_drvdata(kobj_to_dev(kobj));
+	struct catpt_fw_version version;
+	int ret;
+
+	pm_runtime_get_sync(cdev->dev);
+
+	ret = catpt_ipc_get_fw_version(cdev, &version);
+
+	pm_runtime_mark_last_busy(cdev->dev);
+	pm_runtime_put_autosuspend(cdev->dev);
+
+	if (ret)
+		return CATPT_IPC_ERROR(ret);
+
+	memcpy(buf, &version, count);
+	return count;
+}
+
+static BIN_ATTR_RO(fw_build, sizeof(struct catpt_fw_version));
+
+int catpt_sysfs_create(struct catpt_dev *cdev)
+{
+	int ret;
+
+	ret = sysfs_create_file(&cdev->dev->kobj, &dev_attr_fw_version.attr);
+	if (ret)
+		return ret;
+
+	ret = sysfs_create_bin_file(&cdev->dev->kobj, &bin_attr_fw_build);
+	if (ret) {
+		sysfs_remove_file(&cdev->dev->kobj, &dev_attr_fw_version.attr);
+		return ret;
+	}
+
+	return 0;
+}
+
+void catpt_sysfs_remove(struct catpt_dev *cdev)
+{
+	sysfs_remove_bin_file(&cdev->dev->kobj, &bin_attr_fw_build);
+	sysfs_remove_file(&cdev->dev->kobj, &dev_attr_fw_version.attr);
+}