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

I2c_adapter was grabed and never freed #304

Open
alekdu opened this issue Nov 29, 2024 · 0 comments
Open

I2c_adapter was grabed and never freed #304

alekdu opened this issue Nov 29, 2024 · 0 comments

Comments

@alekdu
Copy link

alekdu commented Nov 29, 2024

There are two while loops in this function try to grab and check i2c_adapter. But after check, the i2c_adapter was not put by i2c_put_adapter, so the irrevalent i2c_adapter refcount will be up and never down.

We found this bug in i915 driver unload, since the DP i2c adapter cannot be released ...

int ipu_get_i2c_bus_id(int adapter_id, char *adapter_bdf, int bdf_len)
{
struct i2c_adapter *adapter;
char name[32];
int i = 0;

if (adapter_bdf) {
	while ((adapter = i2c_get_adapter(i)) != NULL) {
		struct device *parent = adapter->dev.parent;
		struct device *pp = parent->parent;

		if (pp && !strncmp(adapter_bdf, dev_name(pp), bdf_len))
			return i;
		i++;
	}
}

i = 0;
snprintf(name, sizeof(name), "i2c_designware.%d", adapter_id);
while ((adapter = i2c_get_adapter(i)) != NULL) {
	struct device *parent = adapter->dev.parent;

	if (parent && !strncmp(name, dev_name(parent), sizeof(name)))
		return i;
	i++;
}

/* Not found, should never happen! */
WARN_ON_ONCE(1);
return -1;

}
EXPORT_SYMBOL_GPL(ipu_get_i2c_bus_id);

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

No branches or pull requests

1 participant