drivers/platform/x86/hp/hp-bioscfg/bioscfg.c:646 hp_add_other_attributes() warn: possible memory leak of 'attr_name_kobj'
kernel test robot
build botBCC: [email protected]
CC: [email protected]
CC: [email protected]
TO: Jorge Lopez <[email protected]>
CC: Hans de Goede <[email protected]>
CC: "Thomas Weißschuh" <[email protected]>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 2cf0f715623872823a72e451243bbf555d10d032 commit: eff3bac88aeda6f10f3b3c5e146e8ce29ff3bfb9 platform/x86: hp-bioscfg: Makefile date: 2 months ago
:::::: branch date: 35 hours ago
:::::: commit date: 2 months ago
config: i386-randconfig-141-20230920 (https://download.01.org/0day-ci/archive/20230920/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230920/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
New smatch warnings:drivers/platform/x86/hp/hp-bioscfg/bioscfg.c:646 hp_add_other_attributes() warn: possible memory leak of 'attr_name_kobj'
Old smatch warnings:drivers/platform/x86/hp/hp-bioscfg/bioscfg.c:637 hp_add_other_attributes() warn: missing error code 'ret'
vim +/attr_name_kobj +646 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
a34fc329b1895f Jorge Lopez 2023-06-08 571
a34fc329b1895f Jorge Lopez 2023-06-08 572 /**
a34fc329b1895f Jorge Lopez 2023-06-08 573 * hp_add_other_attributes() - Initialize HP custom attributes not
a34fc329b1895f Jorge Lopez 2023-06-08 574 * reported by BIOS and required to support Secure Platform and Sure
a34fc329b1895f Jorge Lopez 2023-06-08 575 * Start.
a34fc329b1895f Jorge Lopez 2023-06-08 576 *
a34fc329b1895f Jorge Lopez 2023-06-08 577 * @attr_type: Custom HP attribute not reported by BIOS
a34fc329b1895f Jorge Lopez 2023-06-08 578 *
a34fc329b1895f Jorge Lopez 2023-06-08 579 * Initialize all 2 types of attributes: Platform and Sure Start
a34fc329b1895f Jorge Lopez 2023-06-08 580 * object. Populates each attribute types respective properties
a34fc329b1895f Jorge Lopez 2023-06-08 581 * under sysfs files.
a34fc329b1895f Jorge Lopez 2023-06-08 582 *
a34fc329b1895f Jorge Lopez 2023-06-08 583 * Returns zero(0) if successful. Otherwise, a negative value.
a34fc329b1895f Jorge Lopez 2023-06-08 584 */
a34fc329b1895f Jorge Lopez 2023-06-08 585 static int hp_add_other_attributes(int attr_type)
a34fc329b1895f Jorge Lopez 2023-06-08 586 {
a34fc329b1895f Jorge Lopez 2023-06-08 587 struct kobject *attr_name_kobj;
a34fc329b1895f Jorge Lopez 2023-06-08 588 union acpi_object *obj = NULL;
a34fc329b1895f Jorge Lopez 2023-06-08 589 int ret;
a34fc329b1895f Jorge Lopez 2023-06-08 590 char *attr_name;
a34fc329b1895f Jorge Lopez 2023-06-08 591
a34fc329b1895f Jorge Lopez 2023-06-08 592 mutex_lock(&bioscfg_drv.mutex);
a34fc329b1895f Jorge Lopez 2023-06-08 593
a34fc329b1895f Jorge Lopez 2023-06-08 594 attr_name_kobj = kzalloc(sizeof(*attr_name_kobj), GFP_KERNEL);
a34fc329b1895f Jorge Lopez 2023-06-08 595 if (!attr_name_kobj) {
a34fc329b1895f Jorge Lopez 2023-06-08 596 ret = -ENOMEM;
a34fc329b1895f Jorge Lopez 2023-06-08 597 goto err_other_attr_init;
a34fc329b1895f Jorge Lopez 2023-06-08 598 }
a34fc329b1895f Jorge Lopez 2023-06-08 599
a34fc329b1895f Jorge Lopez 2023-06-08 600 /* Check if attribute type is supported */
a34fc329b1895f Jorge Lopez 2023-06-08 601 switch (attr_type) {
a34fc329b1895f Jorge Lopez 2023-06-08 602 case HPWMI_SECURE_PLATFORM_TYPE:
a34fc329b1895f Jorge Lopez 2023-06-08 603 attr_name_kobj->kset = bioscfg_drv.authentication_dir_kset;
a34fc329b1895f Jorge Lopez 2023-06-08 604 attr_name = SPM_STR;
a34fc329b1895f Jorge Lopez 2023-06-08 605 break;
a34fc329b1895f Jorge Lopez 2023-06-08 606
a34fc329b1895f Jorge Lopez 2023-06-08 607 case HPWMI_SURE_START_TYPE:
a34fc329b1895f Jorge Lopez 2023-06-08 608 attr_name_kobj->kset = bioscfg_drv.main_dir_kset;
a34fc329b1895f Jorge Lopez 2023-06-08 609 attr_name = SURE_START_STR;
a34fc329b1895f Jorge Lopez 2023-06-08 610 break;
a34fc329b1895f Jorge Lopez 2023-06-08 611
a34fc329b1895f Jorge Lopez 2023-06-08 612 default:
a34fc329b1895f Jorge Lopez 2023-06-08 613 pr_err("Error: Unknown attr_type: %d\n", attr_type);
a34fc329b1895f Jorge Lopez 2023-06-08 614 ret = -EINVAL;
a34fc329b1895f Jorge Lopez 2023-06-08 615 goto err_other_attr_init;
a34fc329b1895f Jorge Lopez 2023-06-08 616 }
a34fc329b1895f Jorge Lopez 2023-06-08 617
a34fc329b1895f Jorge Lopez 2023-06-08 618 ret = kobject_init_and_add(attr_name_kobj, &attr_name_ktype,
a34fc329b1895f Jorge Lopez 2023-06-08 619 NULL, "%s", attr_name);
a34fc329b1895f Jorge Lopez 2023-06-08 620 if (ret) {
a34fc329b1895f Jorge Lopez 2023-06-08 621 pr_err("Error encountered [%d]\n", ret);
a34fc329b1895f Jorge Lopez 2023-06-08 622 kobject_put(attr_name_kobj);
a34fc329b1895f Jorge Lopez 2023-06-08 623 goto err_other_attr_init;
a34fc329b1895f Jorge Lopez 2023-06-08 624 }
a34fc329b1895f Jorge Lopez 2023-06-08 625
a34fc329b1895f Jorge Lopez 2023-06-08 626 /* Populate attribute data */
a34fc329b1895f Jorge Lopez 2023-06-08 627 switch (attr_type) {
a34fc329b1895f Jorge Lopez 2023-06-08 628 case HPWMI_SECURE_PLATFORM_TYPE:
a34fc329b1895f Jorge Lopez 2023-06-08 629 ret = hp_populate_secure_platform_data(attr_name_kobj);
a34fc329b1895f Jorge Lopez 2023-06-08 630 break;
a34fc329b1895f Jorge Lopez 2023-06-08 631
a34fc329b1895f Jorge Lopez 2023-06-08 632 case HPWMI_SURE_START_TYPE:
a34fc329b1895f Jorge Lopez 2023-06-08 633 ret = hp_populate_sure_start_data(attr_name_kobj);
a34fc329b1895f Jorge Lopez 2023-06-08 634 break;
a34fc329b1895f Jorge Lopez 2023-06-08 635
a34fc329b1895f Jorge Lopez 2023-06-08 636 default:
a34fc329b1895f Jorge Lopez 2023-06-08 637 goto err_other_attr_init;
a34fc329b1895f Jorge Lopez 2023-06-08 638 }
a34fc329b1895f Jorge Lopez 2023-06-08 639
a34fc329b1895f Jorge Lopez 2023-06-08 640 mutex_unlock(&bioscfg_drv.mutex);
a34fc329b1895f Jorge Lopez 2023-06-08 641 return 0;
a34fc329b1895f Jorge Lopez 2023-06-08 642
a34fc329b1895f Jorge Lopez 2023-06-08 643 err_other_attr_init:
a34fc329b1895f Jorge Lopez 2023-06-08 644 mutex_unlock(&bioscfg_drv.mutex);
a34fc329b1895f Jorge Lopez 2023-06-08 645 kfree(obj);a34fc329b1895f Jorge Lopez 2023-06-08 @646 return ret;a34fc329b1895f Jorge Lopez 2023-06-08 647 }a34fc329b1895f Jorge Lopez 2023-06-08 648
:::::: The code at line 646 was first introduced by commit
:::::: a34fc329b1895fc8a6eb12099adc47009421ba6a platform/x86: hp-bioscfg: bioscfg
:::::: TO: Jorge Lopez <[email protected]>
:::::: CC: Hans de Goede <[email protected]>
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki