* [PATCH] pm8001: Fix potential null pointer dereference and memory leak.
@ 2014-06-17 11:15 Maurizio Lombardi
2014-06-17 12:28 ` Jack Wang
0 siblings, 1 reply; 3+ messages in thread
From: Maurizio Lombardi @ 2014-06-17 11:15 UTC (permalink / raw)
To: xjtuwjp; +Cc: lindar_liu, hch, jbottomley, linux-scsi
The pm8001_get_phy_settings_info() function does not check
the kzalloc() return value and does not free the allocated memory.
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
---
drivers/scsi/pm8001/pm8001_init.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
index c4f31b21..e90c89f 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -677,7 +677,7 @@ static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
* pm8001_get_phy_settings_info : Read phy setting values.
* @pm8001_ha : our hba.
*/
-void pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
+static int pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
{
#ifdef PM8001_READ_VPD
@@ -691,11 +691,15 @@ void pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
payload.offset = 0;
payload.length = 4096;
payload.func_specific = kzalloc(4096, GFP_KERNEL);
+ if (!payload.func_specific)
+ return -ENOMEM;
/* Read phy setting values from flash */
PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
wait_for_completion(&completion);
pm8001_set_phy_profile(pm8001_ha, sizeof(u8), payload.func_specific);
+ kfree(payload.func_specific);
#endif
+ return 0;
}
#ifdef PM8001_USE_MSIX
@@ -879,8 +883,11 @@ static int pm8001_pci_probe(struct pci_dev *pdev,
pm8001_init_sas_add(pm8001_ha);
/* phy setting support for motherboard controller */
if (pdev->subsystem_vendor != PCI_VENDOR_ID_ADAPTEC2 &&
- pdev->subsystem_vendor != 0)
- pm8001_get_phy_settings_info(pm8001_ha);
+ pdev->subsystem_vendor != 0) {
+ rc = pm8001_get_phy_settings_info(pm8001_ha);
+ if (rc)
+ goto err_out_shost;
+ }
pm8001_post_sas_ha_init(shost, chip);
rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
if (rc)
--
Maurizio Lombardi
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] pm8001: Fix potential null pointer dereference and memory leak.
2014-06-17 11:15 [PATCH] pm8001: Fix potential null pointer dereference and memory leak Maurizio Lombardi
@ 2014-06-17 12:28 ` Jack Wang
2014-06-20 7:30 ` Suresh Thiagarajan
0 siblings, 1 reply; 3+ messages in thread
From: Jack Wang @ 2014-06-17 12:28 UTC (permalink / raw)
To: Maurizio Lombardi; +Cc: lindar_liu, hch, jbottomley, linux-scsi
On 06/17/2014 01:15 PM, Maurizio Lombardi wrote:
> The pm8001_get_phy_settings_info() function does not check
> the kzalloc() return value and does not free the allocated memory.
>
> Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
Looks good, thanks
Acked-by: Jack Wang <xjtuwjp@gmail.com>
> ---
> drivers/scsi/pm8001/pm8001_init.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
> index c4f31b21..e90c89f 100644
> --- a/drivers/scsi/pm8001/pm8001_init.c
> +++ b/drivers/scsi/pm8001/pm8001_init.c
> @@ -677,7 +677,7 @@ static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
> * pm8001_get_phy_settings_info : Read phy setting values.
> * @pm8001_ha : our hba.
> */
> -void pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
> +static int pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
> {
>
> #ifdef PM8001_READ_VPD
> @@ -691,11 +691,15 @@ void pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
> payload.offset = 0;
> payload.length = 4096;
> payload.func_specific = kzalloc(4096, GFP_KERNEL);
> + if (!payload.func_specific)
> + return -ENOMEM;
> /* Read phy setting values from flash */
> PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
> wait_for_completion(&completion);
> pm8001_set_phy_profile(pm8001_ha, sizeof(u8), payload.func_specific);
> + kfree(payload.func_specific);
> #endif
> + return 0;
> }
>
> #ifdef PM8001_USE_MSIX
> @@ -879,8 +883,11 @@ static int pm8001_pci_probe(struct pci_dev *pdev,
> pm8001_init_sas_add(pm8001_ha);
> /* phy setting support for motherboard controller */
> if (pdev->subsystem_vendor != PCI_VENDOR_ID_ADAPTEC2 &&
> - pdev->subsystem_vendor != 0)
> - pm8001_get_phy_settings_info(pm8001_ha);
> + pdev->subsystem_vendor != 0) {
> + rc = pm8001_get_phy_settings_info(pm8001_ha);
> + if (rc)
> + goto err_out_shost;
> + }
> pm8001_post_sas_ha_init(shost, chip);
> rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
> if (rc)
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] pm8001: Fix potential null pointer dereference and memory leak.
2014-06-17 12:28 ` Jack Wang
@ 2014-06-20 7:30 ` Suresh Thiagarajan
0 siblings, 0 replies; 3+ messages in thread
From: Suresh Thiagarajan @ 2014-06-20 7:30 UTC (permalink / raw)
To: Jack Wang, Maurizio Lombardi; +Cc: lindar_liu, hch, jbottomley, linux-scsi
On Tue, Jun 17, 2014 at 5:58 PM, Jack Wang <xjtuwjp@gmail.com> wrote:
> On 06/17/2014 01:15 PM, Maurizio Lombardi wrote:
>> The pm8001_get_phy_settings_info() function does not check
>> the kzalloc() return value and does not free the allocated memory.
>>
>> Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
>
> Looks good, thanks
> Acked-by: Jack Wang <xjtuwjp@gmail.com>
Looks good, Thanks Maurizio
Acked-by: Suresh Thiagarajan <Suresh.Thiagarajan@pmcs.com>
>> ---
>> drivers/scsi/pm8001/pm8001_init.c | 13 ++++++++++---
>> 1 file changed, 10 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
>> index c4f31b21..e90c89f 100644
>> --- a/drivers/scsi/pm8001/pm8001_init.c
>> +++ b/drivers/scsi/pm8001/pm8001_init.c
>> @@ -677,7 +677,7 @@ static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
>> * pm8001_get_phy_settings_info : Read phy setting values.
>> * @pm8001_ha : our hba.
>> */
>> -void pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
>> +static int pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
>> {
>>
>> #ifdef PM8001_READ_VPD
>> @@ -691,11 +691,15 @@ void pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
>> payload.offset = 0;
>> payload.length = 4096;
>> payload.func_specific = kzalloc(4096, GFP_KERNEL);
>> + if (!payload.func_specific)
>> + return -ENOMEM;
>> /* Read phy setting values from flash */
>> PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
>> wait_for_completion(&completion);
>> pm8001_set_phy_profile(pm8001_ha, sizeof(u8), payload.func_specific);
>> + kfree(payload.func_specific);
>> #endif
>> + return 0;
>> }
>>
>> #ifdef PM8001_USE_MSIX
>> @@ -879,8 +883,11 @@ static int pm8001_pci_probe(struct pci_dev *pdev,
>> pm8001_init_sas_add(pm8001_ha);
>> /* phy setting support for motherboard controller */
>> if (pdev->subsystem_vendor != PCI_VENDOR_ID_ADAPTEC2 &&
>> - pdev->subsystem_vendor != 0)
>> - pm8001_get_phy_settings_info(pm8001_ha);
>> + pdev->subsystem_vendor != 0) {
>> + rc = pm8001_get_phy_settings_info(pm8001_ha);
>> + if (rc)
>> + goto err_out_shost;
>> + }
>> pm8001_post_sas_ha_init(shost, chip);
>> rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
>> if (rc)
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-06-20 8:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-17 11:15 [PATCH] pm8001: Fix potential null pointer dereference and memory leak Maurizio Lombardi
2014-06-17 12:28 ` Jack Wang
2014-06-20 7:30 ` Suresh Thiagarajan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.