Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nvmem: core: cleanup old eeprom compat entry attributes

file permission are derived based on various configs for
default nvmem sysfs file, reuse it to create the eeprom
compat file too.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20200417121306.23121-1-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Srinivas Kandagatla and committed by
Greg Kroah-Hartman
2a4542e5 3871fdfd

+14 -38
+14 -38
drivers/nvmem/core.c
··· 167 167 return count; 168 168 } 169 169 170 - static umode_t nvmem_bin_attr_is_visible(struct kobject *kobj, 171 - struct bin_attribute *attr, int i) 170 + static umode_t nvmem_bin_attr_get_umode(struct nvmem_device *nvmem) 172 171 { 173 - struct device *dev = container_of(kobj, struct device, kobj); 174 - struct nvmem_device *nvmem = to_nvmem_device(dev); 175 172 umode_t mode = 0400; 176 173 177 174 if (!nvmem->root_only) ··· 184 187 mode &= ~0444; 185 188 186 189 return mode; 190 + } 191 + 192 + static umode_t nvmem_bin_attr_is_visible(struct kobject *kobj, 193 + struct bin_attribute *attr, int i) 194 + { 195 + struct device *dev = container_of(kobj, struct device, kobj); 196 + struct nvmem_device *nvmem = to_nvmem_device(dev); 197 + 198 + return nvmem_bin_attr_get_umode(nvmem); 187 199 } 188 200 189 201 /* default read/write permissions */ ··· 221 215 NULL, 222 216 }; 223 217 224 - /* read only permission */ 225 - static struct bin_attribute bin_attr_ro_nvmem = { 218 + static struct bin_attribute bin_attr_nvmem_eeprom_compat = { 226 219 .attr = { 227 - .name = "nvmem", 228 - .mode = 0444, 229 - }, 230 - .read = bin_attr_nvmem_read, 231 - }; 232 - 233 - /* default read/write permissions, root only */ 234 - static struct bin_attribute bin_attr_rw_root_nvmem = { 235 - .attr = { 236 - .name = "nvmem", 237 - .mode = 0600, 220 + .name = "eeprom", 238 221 }, 239 222 .read = bin_attr_nvmem_read, 240 223 .write = bin_attr_nvmem_write, 241 - }; 242 - 243 - /* read only permission, root only */ 244 - static struct bin_attribute bin_attr_ro_root_nvmem = { 245 - .attr = { 246 - .name = "nvmem", 247 - .mode = 0400, 248 - }, 249 - .read = bin_attr_nvmem_read, 250 224 }; 251 225 252 226 /* ··· 245 259 if (!config->base_dev) 246 260 return -EINVAL; 247 261 248 - if (nvmem->read_only) { 249 - if (config->root_only) 250 - nvmem->eeprom = bin_attr_ro_root_nvmem; 251 - else 252 - nvmem->eeprom = bin_attr_ro_nvmem; 253 - } else { 254 - if (config->root_only) 255 - nvmem->eeprom = bin_attr_rw_root_nvmem; 256 - else 257 - nvmem->eeprom = bin_attr_rw_nvmem; 258 - } 259 - nvmem->eeprom.attr.name = "eeprom"; 262 + nvmem->eeprom = bin_attr_nvmem_eeprom_compat; 263 + nvmem->eeprom.attr.mode = nvmem_bin_attr_get_umode(nvmem); 260 264 nvmem->eeprom.size = nvmem->size; 261 265 #ifdef CONFIG_DEBUG_LOCK_ALLOC 262 266 nvmem->eeprom.attr.key = &eeprom_lock_key;