* [bug report] mtd: parsers: Add Qcom SMEM parser
@ 2021-01-08 12:52 Dan Carpenter
2021-01-08 13:28 ` Manivannan Sadhasivam
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2021-01-08 12:52 UTC (permalink / raw)
To: manivannan.sadhasivam; +Cc: linux-mtd
Hello Manivannan Sadhasivam,
The patch 803eb124e1a6: "mtd: parsers: Add Qcom SMEM parser" from Jan
4, 2021, leads to the following static checker warning:
drivers/mtd/parsers/qcomsmempart.c:109 parse_qcomsmem_part()
warn: passing zero to 'PTR_ERR'
drivers/mtd/parsers/qcomsmempart.c
68 pr_debug("Parsing partition table info from SMEM\n");
69 ptable = qcom_smem_get(SMEM_APPS, SMEM_AARM_PARTITION_TABLE, &len);
70 if (IS_ERR(ptable)) {
Can "ptable" be NULL here?
71 pr_err("Error reading partition table header\n");
72 return PTR_ERR(ptable);
73 }
74
75 /* Verify ptable magic */
76 if (le32_to_cpu(ptable->magic1) != SMEM_FLASH_PART_MAGIC1 ||
77 le32_to_cpu(ptable->magic2) != SMEM_FLASH_PART_MAGIC2) {
78 pr_err("Partition table magic verification failed\n");
79 return -EINVAL;
80 }
81
82 /* Ensure that # of partitions is less than the max we have allocated */
83 numparts = le32_to_cpu(ptable->numparts);
84 if (numparts > SMEM_FLASH_PTABLE_MAX_PARTS_V4) {
85 pr_err("Partition numbers exceed the max limit\n");
86 return -EINVAL;
87 }
88
89 /* Find out length of partition data based on table version */
90 if (le32_to_cpu(ptable->version) <= SMEM_FLASH_PTABLE_V3) {
91 len = SMEM_FLASH_PTABLE_HDR_LEN + SMEM_FLASH_PTABLE_MAX_PARTS_V3 *
92 sizeof(struct smem_flash_pentry);
93 } else if (le32_to_cpu(ptable->version) == SMEM_FLASH_PTABLE_V4) {
94 len = SMEM_FLASH_PTABLE_HDR_LEN + SMEM_FLASH_PTABLE_MAX_PARTS_V4 *
95 sizeof(struct smem_flash_pentry);
96 } else {
97 pr_err("Unknown ptable version (%d)", le32_to_cpu(ptable->version));
98 return -EINVAL;
99 }
100
101 /*
102 * Now that the partition table header has been parsed, verified
103 * and the length of the partition table calculated, read the
104 * complete partition table
105 */
106 ptable = qcom_smem_get(SMEM_APPS, SMEM_AARM_PARTITION_TABLE, &len);
107 if (IS_ERR_OR_NULL(ptable)) {
108 pr_err("Error reading partition table\n");
109 return PTR_ERR(ptable);
If "ptable" is NULL then this code returns success. It's not clear if
that's intentional. If it is then just ignore this email. Thanks!
110 }
111
112 parts = kcalloc(numparts, sizeof(*parts), GFP_KERNEL);
regards,
dan carpenter
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [bug report] mtd: parsers: Add Qcom SMEM parser
2021-01-08 12:52 [bug report] mtd: parsers: Add Qcom SMEM parser Dan Carpenter
@ 2021-01-08 13:28 ` Manivannan Sadhasivam
2021-01-08 14:57 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: Manivannan Sadhasivam @ 2021-01-08 13:28 UTC (permalink / raw)
To: Dan Carpenter; +Cc: linux-mtd
Hi Dan,
On Fri, Jan 08, 2021 at 03:52:41PM +0300, Dan Carpenter wrote:
> Hello Manivannan Sadhasivam,
>
> The patch 803eb124e1a6: "mtd: parsers: Add Qcom SMEM parser" from Jan
> 4, 2021, leads to the following static checker warning:
>
> drivers/mtd/parsers/qcomsmempart.c:109 parse_qcomsmem_part()
> warn: passing zero to 'PTR_ERR'
>
> drivers/mtd/parsers/qcomsmempart.c
> 68 pr_debug("Parsing partition table info from SMEM\n");
> 69 ptable = qcom_smem_get(SMEM_APPS, SMEM_AARM_PARTITION_TABLE, &len);
> 70 if (IS_ERR(ptable)) {
>
> Can "ptable" be NULL here?
>
No it won't. It will return valid error ptr in failure cases.
Thanks,
Mani
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [bug report] mtd: parsers: Add Qcom SMEM parser
2021-01-08 13:28 ` Manivannan Sadhasivam
@ 2021-01-08 14:57 ` Dan Carpenter
0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2021-01-08 14:57 UTC (permalink / raw)
To: Manivannan Sadhasivam; +Cc: linux-mtd
On Fri, Jan 08, 2021 at 06:58:28PM +0530, Manivannan Sadhasivam wrote:
> Hi Dan,
>
> On Fri, Jan 08, 2021 at 03:52:41PM +0300, Dan Carpenter wrote:
> > Hello Manivannan Sadhasivam,
> >
> > The patch 803eb124e1a6: "mtd: parsers: Add Qcom SMEM parser" from Jan
> > 4, 2021, leads to the following static checker warning:
> >
> > drivers/mtd/parsers/qcomsmempart.c:109 parse_qcomsmem_part()
> > warn: passing zero to 'PTR_ERR'
> >
> > drivers/mtd/parsers/qcomsmempart.c
> > 68 pr_debug("Parsing partition table info from SMEM\n");
> > 69 ptable = qcom_smem_get(SMEM_APPS, SMEM_AARM_PARTITION_TABLE, &len);
> > 70 if (IS_ERR(ptable)) {
> >
> > Can "ptable" be NULL here?
> >
>
> No it won't. It will return valid error ptr in failure cases.
The Smatch warning is actually about the IS_ERR_OR_NULL() later. If it
returns NULL then that's counted as success. It's sometimes intentional
but here is seems like qcom_smem_get() never returns NULL so it could
be changed to just IS_ERR().
regards,
dan carpenter
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-08 15:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-08 12:52 [bug report] mtd: parsers: Add Qcom SMEM parser Dan Carpenter
2021-01-08 13:28 ` Manivannan Sadhasivam
2021-01-08 14:57 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).