Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor fixes for driver name rework #731

Merged
merged 2 commits into from
Jul 20, 2023
Merged

Conversation

XinfengZhang
Copy link
Contributor

No description provided.

@@ -686,6 +686,7 @@ static VAStatus va_new_opendriver(VADisplay dpy)
if (vaStatus != VA_STATUS_SUCCESS) {
/* Print and error yet continue, as per the above ordering note */
va_errorMessage(dpy, "vaGetDriverNames() failed with %s\n", vaErrorStr(vaStatus));
num_drivers = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Small nit: let's prefix the commit message with va: .

while (va_drivers[count]) {
if (count < MAX_NAMES && count < *num_drivers)
while (count < MAX_NAMES && va_drivers[count]) {
if (count < *num_drivers)
drivers[count] = strdup(va_drivers[count]);
Copy link
Contributor

Choose a reason for hiding this comment

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

The original code was essentially mixing two conflicting premises:

  • there will be a sentinel - aka the while (va_drivers[count])
  • there will not be a sentinel - aka count < MAX_NAMES

It would be a lot easier to read if we use

for ( ; count < MAX_NAMES && count < *num_drivers; count++)
    drivers[count] = strdup(va_drivers[count]);

Can we use ^^ instead? Plus, please prefix the commit message with drm:

Copy link
Contributor Author

@XinfengZhang XinfengZhang Jul 18, 2023

Choose a reason for hiding this comment

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

Can we use ^^ instead? Plus, please prefix the commit message with drm:

yes, will change the commit message, but

for ( ; count < MAX_NAMES && count < *num_drivers; count++)
    drivers[count] = strdup(va_drivers[count]);

is not enough , if map[i].va_drivers only have 1 element. the pointer map[i].va_drivers[1] is nullptr.

for example, for second map[1], map1.va_drivers[0] = "pvr" map1.va_drivers[1] = null

we always need check drivers[count] is not null.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self: don't write any code before having coffee.

You're right. The following should fix that right?

for ( ; count < MAX_NAMES && va_drivers[count] && count < *num_drivers; count++)
    drivers[count] = strdup(va_drivers[count]);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

of course , but there are a little difference need you to be aware of

if the input parameter --- *num_drivers is 1, the drm_driver is i915.
previous implementation:
num_drivers will be 2 finally, even only first "iHD" will be inserted into drivers[]

after
'''
for ( ; count < MAX_NAMES && va_drivers[count] && count < *num_drivers; count++)
drivers[count] = strdup(va_drivers[count]);
'''
num_drivers will be 1

seems , previous implementation will return the real candidates number, but only first is valid
:)

Copy link
Contributor

@evelikov evelikov Jul 18, 2023

Choose a reason for hiding this comment

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

The API was aimed to take an array + its size as input. Then each implementation should populate the array, up-to the original length and return the actual length. If I'm understanding correctly it sounds like we had bug in the original.

That said, just had a cup of coffee so it would be better if I have another look + send a patch documenting the API later today.

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated. thanks

map is a array, which could be accessed by index, even the index is out of range.
Fixes intel#722

Signed-off-by: Carl Zhang <[email protected]>
@XinfengZhang XinfengZhang force-pushed the fix_722 branch 2 times, most recently from 831b653 to b113c3a Compare July 18, 2023 08:42
@XinfengZhang XinfengZhang merged commit ce9898c into intel:master Jul 20, 2023
13 checks passed
@evelikov
Copy link
Contributor

evelikov commented Jul 20, 2023

Looks like other backends need a similar fix. Let me fix that up... /me writes a patch.

Edit: opened #733

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants