public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org, Kent Russell <kent.russell@amd.com>
Cc: lkp@intel.com, kbuild-all@lists.01.org,
	linux-kernel@vger.kernel.org,
	Alex Deucher <alexander.deucher@amd.com>
Subject: [kbuild] drivers/gpu/drm/amd/amdkfd/kfd_crat.c:801:9: warning: Either the condition '!pcrat_image' is redundant or there is possible null pointer dereference: pcrat_image.
Date: Tue, 27 Oct 2020 20:57:20 +0300	[thread overview]
Message-ID: <20201027175720.GO18329@kadam> (raw)

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git  master
head:   4525c8781ec0701ce824e8bd379ae1b129e26568
commit: d0e63b343e575e8b74c185565b0d79a93494bcaa drm/amdkfd: Use kvmalloc instead of kmalloc for VCRAT
compiler: powerpc64le-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

cppcheck possible warnings: (new ones prefixed by >>, may not real problems)

   In file included from drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_crat.c:
>> drivers/gpu/drm/amd/amdkfd/kfd_crat.c:801:9: warning: Either the condition '!pcrat_image' is redundant or there is possible null pointer dereference: pcrat_image. [nullPointerRedundantCheck]
    memcpy(pcrat_image, crat_table, crat_table->length);
           ^
   drivers/gpu/drm/amd/amdkfd/kfd_crat.c:802:6: note: Assuming that condition '!pcrat_image' is not redundant
    if (!pcrat_image)
        ^
   drivers/gpu/drm/amd/amdkfd/kfd_crat.c:801:9: note: Null pointer dereference
    memcpy(pcrat_image, crat_table, crat_table->length);
           ^
   drivers/gpu/drm/amd/amdkfd/kfd_crat.c:405:32: warning: Shifting signed 32-bit value by 31 bits is undefined behaviour [shiftTooManyBitsSigned]
    if (props && (iolink->flags & CRAT_IOLINK_FLAGS_BI_DIRECTIONAL)) {
                                  ^
   drivers/gpu/drm/amd/amdkfd/kfd_crat.c:1112:26: warning: Shifting signed 32-bit value by 31 bits is undefined behaviour [shiftTooManyBitsSigned]
     sub_type_hdr->flags |= CRAT_IOLINK_FLAGS_BI_DIRECTIONAL;
                            ^
   drivers/gpu/drm/amd/amdkfd/kfd_crat.c:1146:11: warning: Shifting signed 32-bit value by 31 bits is undefined behaviour [shiftTooManyBitsSigned]
             CRAT_IOLINK_FLAGS_BI_DIRECTIONAL;
             ^
   drivers/gpu/drm/amd/amdkfd/kfd_crat.c:941:3: warning: Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]
     sub_type_hdr++;
     ^

vim +801 drivers/gpu/drm/amd/amdkfd/kfd_crat.c

8e05247d4c23ff1 Harish Kasiviswanathan 2017-12-08  772  int kfd_create_crat_image_acpi(void **crat_image, size_t *size)
174de876d6d02f7 Felix Kuehling         2017-12-08  773  {
174de876d6d02f7 Felix Kuehling         2017-12-08  774  	struct acpi_table_header *crat_table;
174de876d6d02f7 Felix Kuehling         2017-12-08  775  	acpi_status status;
8e05247d4c23ff1 Harish Kasiviswanathan 2017-12-08  776  	void *pcrat_image;
174de876d6d02f7 Felix Kuehling         2017-12-08  777  
8e05247d4c23ff1 Harish Kasiviswanathan 2017-12-08  778  	if (!crat_image)
174de876d6d02f7 Felix Kuehling         2017-12-08  779  		return -EINVAL;
174de876d6d02f7 Felix Kuehling         2017-12-08  780  
8e05247d4c23ff1 Harish Kasiviswanathan 2017-12-08  781  	*crat_image = NULL;
8e05247d4c23ff1 Harish Kasiviswanathan 2017-12-08  782  
8e05247d4c23ff1 Harish Kasiviswanathan 2017-12-08  783  	/* Fetch the CRAT table from ACPI */
174de876d6d02f7 Felix Kuehling         2017-12-08  784  	status = acpi_get_table(CRAT_SIGNATURE, 0, &crat_table);
174de876d6d02f7 Felix Kuehling         2017-12-08  785  	if (status == AE_NOT_FOUND) {
174de876d6d02f7 Felix Kuehling         2017-12-08  786  		pr_warn("CRAT table not found\n");
174de876d6d02f7 Felix Kuehling         2017-12-08  787  		return -ENODATA;
174de876d6d02f7 Felix Kuehling         2017-12-08  788  	} else if (ACPI_FAILURE(status)) {
174de876d6d02f7 Felix Kuehling         2017-12-08  789  		const char *err = acpi_format_exception(status);
174de876d6d02f7 Felix Kuehling         2017-12-08  790  
174de876d6d02f7 Felix Kuehling         2017-12-08  791  		pr_err("CRAT table error: %s\n", err);
174de876d6d02f7 Felix Kuehling         2017-12-08  792  		return -EINVAL;
174de876d6d02f7 Felix Kuehling         2017-12-08  793  	}
174de876d6d02f7 Felix Kuehling         2017-12-08  794  
6127896f4a27257 Huang Rui              2020-08-18  795  	if (kfd_ignore_crat()) {
ebcfd1e276207e4 Felix Kuehling         2017-12-08  796  		pr_info("CRAT table disabled by module option\n");
ebcfd1e276207e4 Felix Kuehling         2017-12-08  797  		return -ENODATA;
ebcfd1e276207e4 Felix Kuehling         2017-12-08  798  	}
ebcfd1e276207e4 Felix Kuehling         2017-12-08  799  
d0e63b343e575e8 Kent Russell           2020-09-18  800  	pcrat_image = kvmalloc(crat_table->length, GFP_KERNEL);
d0e63b343e575e8 Kent Russell           2020-09-18 @801  	memcpy(pcrat_image, crat_table, crat_table->length);
                                                                       ^^^^^^^^^^^
Dereferenced before the check for NULL

8e05247d4c23ff1 Harish Kasiviswanathan 2017-12-08  802  	if (!pcrat_image)
                                                                    ^^^^^^^^^^^^
Check.

8e05247d4c23ff1 Harish Kasiviswanathan 2017-12-08  803  		return -ENOMEM;
174de876d6d02f7 Felix Kuehling         2017-12-08  804  
8e05247d4c23ff1 Harish Kasiviswanathan 2017-12-08  805  	*crat_image = pcrat_image;
174de876d6d02f7 Felix Kuehling         2017-12-08  806  	*size = crat_table->length;
174de876d6d02f7 Felix Kuehling         2017-12-08  807  
174de876d6d02f7 Felix Kuehling         2017-12-08  808  	return 0;
174de876d6d02f7 Felix Kuehling         2017-12-08  809  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org 
_______________________________________________
kbuild mailing list -- kbuild@lists.01.org
To unsubscribe send an email to kbuild-leave@lists.01.org

                 reply	other threads:[~2020-10-27 18:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201027175720.GO18329@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=alexander.deucher@amd.com \
    --cc=kbuild-all@lists.01.org \
    --cc=kbuild@lists.01.org \
    --cc=kent.russell@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox