lkml.org 
[lkml]   [2020]   [May]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v5 6/6] soc/tegra: Expose Boot Configuration Table via sysfs
On Sat, May 16, 2020 at 06:36:44PM +0300, Dmitry Osipenko wrote:
> It's quite useful to have unencrypted BCT exposed to userspace for
> debugging purposes, so let's expose it via sysfs. The BCT data will be
> present in '/sys/tegra/boot_config_table' binary file if BCT is available.
[...]
> +/*
> + * spare_bct[] will be released once kernel is booted, hence not wasting
> + * kernel space if BCT is missing. The tegra_bct can't be allocated during
> + * of BCT setting up because it's too early for the slab allocator.
> + */
> +static u8 spare_bct[SZ_8K] __initdata;
> +static u8 *tegra_bct;
> +
> +static ssize_t boot_config_table_read(struct file *filp,
> + struct kobject *kobj,
> + struct bin_attribute *bin_attr,
> + char *buf, loff_t off, size_t count)
> +{
> + memcpy(buf, tegra_bct + off, count);
> + return count;
> +}
> +static BIN_ATTR_RO(boot_config_table, 0);
> +
> +static int __init tegra_bootdata_bct_sysfs_init(void)
> +{
> + if (!bin_attr_boot_config_table.size)
> + return 0;
> +
> + tegra_bct = kmalloc(GFP_KERNEL, bin_attr_boot_config_table.size);
> + if (!tegra_bct)
> + return -ENOMEM;
> +
> + memcpy(tegra_bct, spare_bct, bin_attr_boot_config_table.size);
> +
> + return sysfs_create_bin_file(tegra_soc_kobj,
> + &bin_attr_boot_config_table);

Should we consider freeing the table if sysfs registration fails?

> +}
> +late_initcall(tegra_bootdata_bct_sysfs_init)
> +
> +void __init tegra_bootdata_bct_setup(void __iomem *bct_ptr, size_t bct_size)
> +{
> + memcpy_fromio(spare_bct, bct_ptr, bct_size);
> + bin_attr_boot_config_table.size = bct_size;
[...]

The size isn't checked anywhere. How the maximum is obtained? At least
a comment would be good if the 8k limit is guaranteed by other means.

Best Regards,
Michał Mirosław

\
 
 \ /
  Last update: 2020-05-18 09:46    [W:1.286 / U:0.144 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site