diff mbox

[1/2] media: s5p-mfc: check for firmware allocation before requesting firmware

Message ID e7c1ad0167ca363cc783be11871a04957127a3fa.1507325072.git.shuahkh@osg.samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

Shuah Khan Oct. 6, 2017, 9:30 p.m. UTC
Check if firmware is allocated before requesting firmware instead of
requesting firmware only to release it if firmware is not allocated.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Andrzej Hajda Nov. 2, 2017, 8:12 a.m. UTC | #1
Hi Shuah,

On 06.10.2017 23:30, Shuah Khan wrote:
> Check if firmware is allocated before requesting firmware instead of
> requesting firmware only to release it if firmware is not allocated.
>
> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> ---
>  drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
> index 69ef9c2..f064a0d1 100644
> --- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
> @@ -55,6 +55,11 @@ int s5p_mfc_load_firmware(struct s5p_mfc_dev *dev)
>  	 * into kernel. */
>  	mfc_debug_enter();
>  
> +	if (!dev->fw_buf.virt) {
> +		mfc_err("MFC firmware is not allocated\n");
> +		return -EINVAL;
> +	}
> +
>  	for (i = MFC_FW_MAX_VERSIONS - 1; i >= 0; i--) {
>  		if (!dev->variant->fw_name[i])
>  			continue;
> @@ -75,11 +80,6 @@ int s5p_mfc_load_firmware(struct s5p_mfc_dev *dev)
>  		release_firmware(fw_blob);
>  		return -ENOMEM;
>  	}
> -	if (!dev->fw_buf.virt) {
> -		mfc_err("MFC firmware is not allocated\n");
> -		release_firmware(fw_blob);
> -		return -EINVAL;
> -	}

Is there any scenario in which dev->fw_buf.virt is null and
s5p_mfc_load_firmware is called?
I suspect this check is not necessary at all.

Regards
Andrzej

>  	memcpy(dev->fw_buf.virt, fw_blob->data, fw_blob->size);
>  	wmb();
>  	release_firmware(fw_blob);
Shuah Khan Nov. 3, 2017, 12:23 a.m. UTC | #2
On 11/02/2017 02:12 AM, Andrzej Hajda wrote:
> Hi Shuah,
> 
> On 06.10.2017 23:30, Shuah Khan wrote:
>> Check if firmware is allocated before requesting firmware instead of
>> requesting firmware only to release it if firmware is not allocated.
>>
>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
>> ---
>>  drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c | 10 +++++-----
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
>> index 69ef9c2..f064a0d1 100644
>> --- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
>> +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
>> @@ -55,6 +55,11 @@ int s5p_mfc_load_firmware(struct s5p_mfc_dev *dev)
>>  	 * into kernel. */
>>  	mfc_debug_enter();
>>  
>> +	if (!dev->fw_buf.virt) {
>> +		mfc_err("MFC firmware is not allocated\n");
>> +		return -EINVAL;
>> +	}
>> +
>>  	for (i = MFC_FW_MAX_VERSIONS - 1; i >= 0; i--) {
>>  		if (!dev->variant->fw_name[i])
>>  			continue;
>> @@ -75,11 +80,6 @@ int s5p_mfc_load_firmware(struct s5p_mfc_dev *dev)
>>  		release_firmware(fw_blob);
>>  		return -ENOMEM;
>>  	}
>> -	if (!dev->fw_buf.virt) {
>> -		mfc_err("MFC firmware is not allocated\n");
>> -		release_firmware(fw_blob);
>> -		return -EINVAL;
>> -	}
> 
> Is there any scenario in which dev->fw_buf.virt is null and
> s5p_mfc_load_firmware is called?
> I suspect this check is not necessary at all.
> 

I don't believe so. Allocation is done in s5p_mfc_configure_dma_memory()
code path and if that fails it bails out of _probe. I can remove the check
all together.

thanks,
-- Shuah
diff mbox

Patch

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index 69ef9c2..f064a0d1 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -55,6 +55,11 @@  int s5p_mfc_load_firmware(struct s5p_mfc_dev *dev)
 	 * into kernel. */
 	mfc_debug_enter();
 
+	if (!dev->fw_buf.virt) {
+		mfc_err("MFC firmware is not allocated\n");
+		return -EINVAL;
+	}
+
 	for (i = MFC_FW_MAX_VERSIONS - 1; i >= 0; i--) {
 		if (!dev->variant->fw_name[i])
 			continue;
@@ -75,11 +80,6 @@  int s5p_mfc_load_firmware(struct s5p_mfc_dev *dev)
 		release_firmware(fw_blob);
 		return -ENOMEM;
 	}
-	if (!dev->fw_buf.virt) {
-		mfc_err("MFC firmware is not allocated\n");
-		release_firmware(fw_blob);
-		return -EINVAL;
-	}
 	memcpy(dev->fw_buf.virt, fw_blob->data, fw_blob->size);
 	wmb();
 	release_firmware(fw_blob);