Skip to content

smart_amp: fix return errors#9387

Merged
lgirdwood merged 1 commit intothesofproject:mainfrom
cujomalainey:smart-fix
Aug 23, 2024
Merged

smart_amp: fix return errors#9387
lgirdwood merged 1 commit intothesofproject:mainfrom
cujomalainey:smart-fix

Conversation

@cujomalainey
Copy link
Contributor

If 0 is a error then override it so the outer function doesn't think we ran successfully and then hit a null ptr after we freed everything.

@cujomalainey cujomalainey added the bug Something isn't working as expected label Aug 22, 2024
if (ret <= 0)
if (ret <= 0) {
if (ret == 0)
ret = -EINVAL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll propose to return early without error

if (ret < 0)
    goto error;

/* no memory requirement */ 
if (ret == 0)
    return 0;

/* allocate the memory block when returned size > 0. */
...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also call this out in an inline comment that 0 here is an error code from smart amp (otherwise people will try and fix)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what @johnylin76 is saying is that its not an error and was incorrectly treated as it if it was an error. I believe 0 is "not needed" and shouldnt have been triggering the error path.

@@ -111,8 +111,11 @@ static ssize_t smart_amp_alloc_mod_memblk(struct smart_amp_data *sad,

/* query the required size from inner model. */
ret = mod->mod_ops->query_memblk_size(mod, blk);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnylin76 FYI we are exploring 64bit builds now so sizes might differ between builds. It might be wiser to have the API use ssize_t rather than int. Minor nit for you to consider.

If 0 is a error then override it so the outer function doesn't think we ran
successfully and then hit a null ptr after we freed everything.

Signed-off-by: Curtis Malainey <cujomalainey@chromium.org>
@lgirdwood lgirdwood merged commit 2f64bde into thesofproject:main Aug 23, 2024
@cujomalainey cujomalainey deleted the smart-fix branch August 23, 2024 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants