summaryrefslogtreecommitdiffstats
path: root/drivers/staging/greybus/power_supply.c
Commit message (Collapse)AuthorAgeFilesLines
* greybus: use PTR_ERR_OR_ZERO()Alex Elder2016-05-271-4/+1
| | | | | | | | | | | | Coccinelle points out that the macro PTR_ERR_OR_ZERO() handles the frequent case of converting a pointer into either error code (if its value is an encoded error value) or 0 (otherwise). Switch some code in gb_power_supply_register() to use that macro. I have verified this is true of the kernel we're now working with (arche-6.0). Signed-off-by: Alex Elder <elder@linaro.org> Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: convert drivers to use connection->private set/getGreg Kroah-Hartman2016-03-221-2/+2
| | | | | | | | | | This converts all drivers to use the gb_connection_get_data() and gb_connection_set_data() functions to make it a bit more explicit as to what is going on. Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Reviewed-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: power_supply: reverse version check for new psy APISandeep Patil2016-03-161-4/+4
| | | | | | | | | | | | | | | Reversing the kernel version check for new power supply APIs will easily allow us to use older kernels with backported power supply APIs by defining "CORE_OWNS_PSY_STRUCT" in power supply core header Testing Done: - Build tested with arche kernel with backported power supply APIs - Build tested also with current arche kernel to make sure we build with 3.10 kernels Signed-off-by: Sandeep Patil <sspatil@google.com> Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: power_supply: convert to bundle driverViresh Kumar2016-02-151-17/+55
| | | | | | | | | | | Convert the legacy power_supply protocol driver to a bundle driver. This also fixes a potential crash should a (malicious) module have sent an early request before the private data had been initialised. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Reviewed-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: power_supply: Break supply setup into two partsViresh Kumar2016-02-151-13/+44
| | | | | | | | | | | | | | | This breaks the power supply setup routine into two parts, the first one allocates all the necessary resources and the second on registers supplies to the required frameworks. This is required to enable only TX on the connection, until we have allocated all the resources, otherwise the request handler might get called for partially initialized structures. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org> Reviewed-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: power_supply: rework get descriptorsRui Miguel Silva2016-02-051-20/+37
| | | | | | | | | | | | | | | | | | | | | | | Rework the get property descriptors function to fix a memory handling error for the response structure. This could corrupt the stack and throw nonalignment PC or SP error: Internal error: SP or PC abort: 8a000000 1 PREEMPT SMP Modules linked in: gb_power_supply(O) gb_arche(O) gb_camera(O) gb_es2(O) gb_vibrator(O) gb_raw(O) g] CPU: 3 PID: 51 Comm: kworker/u16:2 Tainted: G W O 3.10.73-g8a6af60-00118-g599a5c1 #1 Workqueue: greybus1:svc gb_svc_connection_destroy [greybus] task: ffffffc0ba249580 ti: ffffffc0ba294000 task.ti: ffffffc0ba294000 PC is at gb_power_supply_connection_init+0x81/0x1dc [gb_power_supply] LR is at gb_power_supply_connection_init+0x81/0x1dc [gb_power_supply] pc : [<ffffffbffc03b901>] lr : [<ffffffbffc03b901>] pstate: 80000145 sp : ffffffc0ba297a00 x29: 32002e002a001100 x28: ffffffc042cb2c80 To fix this, allocate firstly the operation and handle request and response using operation payload. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: power_supply: fix check for configured supplyRui Miguel Silva2016-01-121-1/+2
| | | | | | | | | | The correct check for if the power supply is ready to receive event is wrong and it should check for the registered flag. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Reported-by: Johan Hovold <johan@hovoldconsulting.com> Reviewed-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: power_supply: fix use after free of power supplyRui Miguel Silva2016-01-111-3/+1
| | | | | | | | | | | | | Individual power supply were being freed and checked using the wrong pointers and at the wrong place, which would make several issues, like used after free and so on. Fix it by freeing all allocated memory after release individual power supply. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Reported-by: Johan Hovold <johan@hovoldconsulting.com> Reviewed-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: power_supply: fix leak getting string propertiesRui Miguel Silva2016-01-111-5/+3
| | | | | | | | | When fetching string properties, memory was being allocated and leaked when it was not necessary to do so. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Reviewed-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: power_supply: fix error path at supplies setupRui Miguel Silva2016-01-111-1/+6
| | | | | | | | | | | | | If something goes wrong at setup time for the supplies, we need to release all the resources allocated already. Call the supplies release function which will handle the correct teardown of the supplies. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Reported-by: Johan Hovold <johan@hovoldconsulting.com> Reviewed-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: power_supply: free supplies at releaseRui Miguel Silva2016-01-111-0/+1
| | | | | | | | | | After freeing each individual power_supply, free the top controller, if not it will leak memory at each module insert/remove. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Reported-by: Johan Hovold <johan@hovoldconsulting.com> Reviewed-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: power_supply: fix unregister on error pathRui Miguel Silva2016-01-111-2/+8
| | | | | | | | | | | If setup fail the release for each supply needs to know the status at unregister time. So, add the field to the structure, update it at setup time and use it at release. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Reported-by: Johan Hovold <johan@hovoldconsulting.com> Reviewed-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: power_supply: do not release failed supply allocRui Miguel Silva2016-01-111-0/+3
| | | | | | | | | | If allocation of memory for each supply fail, we should get out of release any individual supply. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Reported-by: Johan Hovold <johan@hovoldconsulting.com> Reviewed-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: power_supply: fix lock imbalance in init error pathJohan Hovold2016-01-111-2/+4
| | | | | | | | | Make sure to release the supplies_lock before returning on errors in gb_power_supplies_setup(). Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: power_supply: rework and operation changesRui Miguel Silva2015-11-121-205/+639
| | | | | | | | | | | | | | | | This is a major rework and changes to the current implementation of the battery protocol. The previous implementation lack the support of a more dynamic handle of power supply properties and updating of status. Also, reflect the actual state of the greybus specification So, with this new approach a set of operations to fetch the battery module configuration and properties is add, new methods to cache and update the values of properties, new operation to set properties if declared writable and an event operation that can be triggered by the module to force an update read on the properties values. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: battery: move implementation to power_supplyRui Miguel Silva2015-11-121-76/+79
| | | | | | | | | | Rename protocol to POWER_SUPPLY and implementation details from battery to power_supply. Also fix some tabs between define and macro name. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
* greybus: battery: move battery file to power_supplyRui Miguel Silva2015-11-121-0/+317
Rename the battery.c to power_supply.c and update the makefile as the Greybus protocol is being renamed from battery to power_supply. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
OpenPOWER on IntegriCloud