From 9330da939c87ab440a2c6aed9d1e2aff61c3f95c Mon Sep 17 00:00:00 2001 From: Venkata Rao Kakani Date: Wed, 27 Jan 2021 19:56:05 +0530 Subject: [PATCH] drivers: soc: rename block device nodes Rename block driver enables the renaming of block dev nodes assigned by generic driver. Change-Id: I40f966717683efb9800dcb34ed851f95cb22e3c8 Signed-off-by: Venkata Rao Kakani --- drivers/soc/qcom/Kconfig | 9 ++++ drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/rename_block_device.c | 58 ++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 drivers/soc/qcom/rename_block_device.c diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index f12c44670896..9e4b3e29bf9d 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -1156,5 +1156,14 @@ config QCOM_RTIC will trigger RTIC kernel MP.s (measurement parameters) generation during the kernel build. +config RENAME_BLOCK_DEVICE + tristate "Rename block device node in /dev" + default n + help + Say 'Y' to to rename the block device node assigned by generic + driver to a name that is needed. This is used for rename block + device names created by default as sda1, sda2 etc. to the + names system is needed.this is applicable for block devices only. + source "drivers/soc/qcom/icnss2/Kconfig" endmenu diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index 2bc2b758bc43..d37792330201 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -104,3 +104,4 @@ obj-$(CONFIG_QTI_HW_MEMLAT_SCMI_CLIENT) += memlat_scmi.o obj-$(CONFIG_QTI_HW_MEMLAT) += rimps_memlat.o obj-$(CONFIG_QTI_HW_MEMLAT_LOG) += rimps_log.o obj-$(CONFIG_QCOM_QFPROM_SYS) += qfprom-sys.o +obj-$(CONFIG_RENAME_BLOCK_DEVICE) += rename_block_device.o diff --git a/drivers/soc/qcom/rename_block_device.c b/drivers/soc/qcom/rename_block_device.c new file mode 100644 index 000000000000..917482077b6b --- /dev/null +++ b/drivers/soc/qcom/rename_block_device.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2021, The Linux Foundation. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#define PATH_SIZE 32 + +static int rename_blk_dev_init(void) +{ + dev_t dev; + int index = 0, partno; + struct gendisk *disk; + struct device_node *node; + char dev_path[PATH_SIZE]; + const char *actual_name, *modified_name; + + node = of_find_compatible_node(NULL, NULL, "qcom,blkdev-rename"); + if (!node) { + pr_err("qcom,blkdev-rename is missing\n"); + goto out; + } + while (!of_property_read_string_index(node, "actual-dev", index, + &actual_name)) { + memset(dev_path, '\0', PATH_SIZE); + snprintf(dev_path, PATH_SIZE, "/dev/%s", actual_name); + dev = name_to_dev_t(dev_path); + if (!dev) { + pr_err("No device path : %s\n", dev_path); + return -EINVAL; + } + disk = get_gendisk(dev, &partno); + if (!disk) { + pr_err("No device with dev path : %s\n", dev_path); + return -ENXIO; + } + if (!of_property_read_string_index(node, "rename-dev", index, + &modified_name)) { + device_rename(disk_to_dev(disk), modified_name); + } else { + pr_err("rename-dev for actual-dev = %s is missing\n", + actual_name); + return -ENXIO; + } + index++; + } +out: + return 0; +} + +late_initcall(rename_blk_dev_init); +MODULE_DESCRIPTION("Rename block devices"); +MODULE_LICENSE("GPL v2");