Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d6f83894 authored by Stephen Boyd's avatar Stephen Boyd Committed by Jiri Kosina
Browse files

HID: i2c-hid: Use devm to allocate i2c_hid struct



Use devm here to save some lines and prepare for bulk regulator usage in
this driver. Otherwise, when we devm bulk get regulators we'll free the
containing i2c_hid structure and try to put regulator pointers from
freed memory.

Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Dmitry Torokhov <dtor@chromium.org>
Cc: Doug Anderson <dianders@chromium.org>
Signed-off-by: default avatarStephen Boyd <swboyd@chromium.org>
Acked-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent fdea70d2
Loading
Loading
Loading
Loading
+3 −6
Original line number Original line Diff line number Diff line
@@ -1002,18 +1002,18 @@ static int i2c_hid_probe(struct i2c_client *client,
		return client->irq;
		return client->irq;
	}
	}


	ihid = kzalloc(sizeof(struct i2c_hid), GFP_KERNEL);
	ihid = devm_kzalloc(&client->dev, sizeof(*ihid), GFP_KERNEL);
	if (!ihid)
	if (!ihid)
		return -ENOMEM;
		return -ENOMEM;


	if (client->dev.of_node) {
	if (client->dev.of_node) {
		ret = i2c_hid_of_probe(client, &ihid->pdata);
		ret = i2c_hid_of_probe(client, &ihid->pdata);
		if (ret)
		if (ret)
			goto err;
			return ret;
	} else if (!platform_data) {
	} else if (!platform_data) {
		ret = i2c_hid_acpi_pdata(client, &ihid->pdata);
		ret = i2c_hid_acpi_pdata(client, &ihid->pdata);
		if (ret)
		if (ret)
			goto err;
			return ret;
	} else {
	} else {
		ihid->pdata = *platform_data;
		ihid->pdata = *platform_data;
	}
	}
@@ -1126,7 +1126,6 @@ static int i2c_hid_probe(struct i2c_client *client,


err:
err:
	i2c_hid_free_buffers(ihid);
	i2c_hid_free_buffers(ihid);
	kfree(ihid);
	return ret;
	return ret;
}
}


@@ -1150,8 +1149,6 @@ static int i2c_hid_remove(struct i2c_client *client)


	regulator_disable(ihid->pdata.supply);
	regulator_disable(ihid->pdata.supply);


	kfree(ihid);

	return 0;
	return 0;
}
}