1
0
Fork 0
Commit Graph

32 Commits (redonkable)

Author SHA1 Message Date
Greg Kroah-Hartman ec0ad86817 staging: greybus: move core include files to include/linux/greybus/
With the goal of moving the core of the greybus code out of staging, the
include files need to be moved to include/linux/greybus.h and
include/linux/greybus/

Cc: Vaibhav Hiremath <hvaibhav.linux@gmail.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: Vaibhav Agarwal <vaibhav.sr@gmail.com>
Cc: Rui Miguel Silva <rmfrfs@gmail.com>
Cc: David Lin <dtwlin@gmail.com>
Cc: "Bryan O'Donoghue" <pure.logic@nexus-software.ie>
Cc: greybus-dev@lists.linaro.org
Cc: devel@driverdev.osuosl.org
Acked-by: Mark Greer <mgreer@animalcreek.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Alex Elder <elder@kernel.org>
Link: https://lore.kernel.org/r/20190825055429.18547-8-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-27 19:02:59 +02:00
Gustavo A. R. Silva 827c085bae staging: greybus: power_supply: use struct_size() helper
Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes, in particular in the
context in which this code is being used.

So, replace code of the following form:

sizeof(*resp) + props_count * sizeof(struct gb_power_supply_props_desc)

with:

struct_size(resp, props, props_count)

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-19 15:03:07 +02:00
Johan Hovold 47830c1127 staging: greybus: power_supply: fix prop-descriptor request size
Since moving the message buffers off the stack, the dynamically
allocated get-prop-descriptor request buffer is incorrectly sized due to
using the pointer rather than request-struct size when creating the
operation.

Fortunately, the pointer size is always larger than this one-byte
request, but this could still cause trouble on the remote end due to the
unexpected message size.

Fixes: 9d15134d06 ("greybus: power_supply: rework get descriptors")
Cc: stable <stable@vger.kernel.org>     # 4.9
Cc: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-16 13:22:51 +02:00
Greg Kroah-Hartman 863dbc52e7 staging: greybus: Remove redundant license text
Now that the SPDX tag is in all greybus files, that identifies the
license in a specific and legally-defined manner.  So the extra GPL text
wording can be removed as it is no longer needed at all.

This is done on a quest to remove the 700+ different ways that files in
the kernel describe the GPL license text.  And there's unneeded stuff
like the address (sometimes incorrect) for the FSF which is never
needed.

No copyright headers or other non-license-description text was removed.

Cc: Vaibhav Hiremath <hvaibhav.linux@gmail.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Acked-by: Vaibhav Agarwal <vaibhav.sr@gmail.com>
Acked-by: David Lin <dtwlin@gmail.com>
Acked-by: Johan Hovold <johan@kernel.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Mark Greer <mgreer@animalcreek.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Acked-by: "Bryan O'Donoghue" <pure.logic@nexus-software.ie>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-11 14:46:21 +01:00
Greg Kroah-Hartman eb50fd3a22 staging: greybus: add SPDX identifiers to all greybus driver files
It's good to have SPDX identifiers in all files to make it easier to
audit the kernel tree for correct licenses.

Update the drivers/staging/greybus files files with the correct SPDX
license identifier based on the license text in the file itself.  The
SPDX identifier is a legally binding shorthand, which can be used
instead of the full boiler plate text.

This work is based on a script and data from Thomas Gleixner, Philippe
Ombredanne, and Kate Stewart.

Cc: Vaibhav Hiremath <hvaibhav.linux@gmail.com>
Cc: "Bryan O'Donoghue" <pure.logic@nexus-software.ie>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Philippe Ombredanne <pombredanne@nexb.com>
Acked-by: Vaibhav Agarwal <vaibhav.sr@gmail.com>
Acked-by: David Lin <dtwlin@gmail.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Acked-by: Johan Hovold <johan@kernel.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Mark Greer <mgreer@animalcreek.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-11 14:46:20 +01:00
JB Van Puyvelde 03d261deea staging: greybus: power_supply: replace kzalloc by kcalloc
According to checkpatch.pl, kcalloc should be preferred to kzalloc with
multiply.

Signed-off-by: JB Van Puyvelde <jbvanpuyvelde@gmail.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-05-15 07:41:59 +02:00
Rui Miguel Silva 722a133a6a staging: greybus: power_supply: remove KERNEL_VERSION checks
No need to support older kernel versions in the Greybus Power Supply
driver, so remove the checks as needed, we can now rely on all of the
correct Power Supply core apis being present. Also move some properties
definitions to the power supply greybus code.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-09-19 16:48:44 +02:00
Philip Yang 4e013b64c1 greybus: power_supply: Add runtime pm support
Modify Power_supply greybus driver to support runtime PM framework.

During charging state, the driver will block remote device of suspending,
and then enables runtime suspend when remote device is in none chargin
state.

Testing Done: Compiled and verified on EVT2, EVT2 1x2 GPB test module
              and Device class daughter board.

Signed-off-by: Philip Yang <yang_philip@projectara.com>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-09-02 14:13:39 +02:00
Rui Miguel Silva 6ac9166d4e greybus: power_supply: fix name setting location
We were checking for existing power supply names in the wrong place,
i.e, we were checking before any of the module power supply were
registered, because of that of course no name collision was detected.

Move the check to the register loop and with that we guarantee that this
mechanism works for greybus power supply naming.

Tested: using gbsim and using power supply with the same name and check
that: 1. no problems creating sysfs entries; 2. naming is done following
the desired rules.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-08-26 13:16:11 +02:00
Rui Miguel Silva b5fbe819af greybus: power_supply: invalidate cache at update request
When we receive a update request we shall not trust the cache mechanism
and for that we need a way to invalidate the cache. Add a field that
will control the cache status and refactor the code to check if cache is
valid in a helper function.

This will fix the scenario where an update request is received within
the cache expiration time after a previous update as happened and would
be ignored.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-08-18 17:34:01 +02:00
Rui Miguel Silva 5f66d62e83 greybus: power_supply: fix update interval check at request handler
We use the update interval to control the remove path and we set it to
zero when we do not want to have more updates in transit. That means
that the check in the request handler needs to be for interval update
zero to discard the newly received request and not the other way around
like it is.

This will fix the issue that all incoming requests were being discard.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-08-18 17:34:01 +02:00
Rui Miguel Silva c4582f9d79 greybus: power_supply: add callback to handle power supply changes
When checking for property changes we may need to act upon that change
besides reporting it using power_supply_changed. So, add a function that
will be call if the specific property changed.

As at it, adjust some indentation of the psy_props_changes array.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-08-18 17:34:01 +02:00
Rui Miguel Silva 47becc556d greybus: power_supply: convert greybus properties to power supply properties
We need to translate greybus properties to power supply core properties,
for that when parsing the properties that were fetch during
configuration we check if there is a match to the running kernel version
and store it in a new field (gb_prop) in the gb_power_supply_prop
struct.

If the corresponding property does not exist in the running
kernel (because of version or vendor specific property) we drop that
property.

A collection of properties that, at this time, may diverge are defined
in the kernel_ver.h to avoid breakage at build time and run time if this
properties are not supported by the kernel.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-16 07:55:41 +09:00
Rui Miguel Silva 6e720c277a greybus: power_supply: change property values to integer
To align with power supply core values type (integer) move the val and
previous_val to integer also.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-16 07:55:41 +09:00
Viresh Kumar 60fb3405c7 greybus: Remove extra blank lines
This patch removes few blank lines across the repository at places where
two blank lines were present together or when a blank line is present at
the start or end of a routine.

Note that this doesn't remove most of them from greybus_protocols.h as
they were added on purpose.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-10 16:32:33 -07:00
Alex Elder 95073cc2e5 greybus: use PTR_ERR_OR_ZERO()
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>
2016-05-27 11:28:16 -07:00
Greg Kroah-Hartman 0ec3063244 greybus: convert drivers to use connection->private set/get
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>
2016-03-22 16:47:28 -04:00
Sandeep Patil f8811c7630 greybus: power_supply: reverse version check for new psy API
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>
2016-03-16 21:49:31 -07:00
Viresh Kumar 68b1309be6 greybus: power_supply: convert to bundle driver
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>
2016-02-15 14:53:43 -08:00
Viresh Kumar 7e9fba8df7 greybus: power_supply: Break supply setup into two parts
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>
2016-02-15 14:53:43 -08:00
Rui Miguel Silva 9d15134d06 greybus: power_supply: rework get descriptors
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>
2016-02-05 16:37:34 -08:00
Rui Miguel Silva adb57cff54 greybus: power_supply: fix check for configured supply
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>
2016-01-12 11:21:35 -08:00
Rui Miguel Silva accad1ba7d greybus: power_supply: fix use after free of power supply
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>
2016-01-11 19:18:14 -08:00
Rui Miguel Silva f921fb139b greybus: power_supply: fix leak getting string properties
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>
2016-01-11 19:18:14 -08:00
Rui Miguel Silva d9eafd58e3 greybus: power_supply: fix error path at supplies setup
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>
2016-01-11 19:18:14 -08:00
Rui Miguel Silva 23f25ba6ed greybus: power_supply: free supplies at release
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>
2016-01-11 19:18:14 -08:00
Rui Miguel Silva ff85f723ca greybus: power_supply: fix unregister on error path
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>
2016-01-11 19:18:14 -08:00
Rui Miguel Silva 7ccac20d59 greybus: power_supply: do not release failed supply alloc
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>
2016-01-11 19:18:14 -08:00
Johan Hovold e0d91ff127 greybus: power_supply: fix lock imbalance in init error path
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>
2016-01-11 19:16:12 -08:00
Rui Miguel Silva ffe2e2487a greybus: power_supply: rework and operation changes
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>
2015-11-12 16:12:55 -08:00
Rui Miguel Silva 2724be0305 greybus: battery: move implementation to power_supply
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>
2015-11-12 16:08:40 -08:00
Rui Miguel Silva 464888410d greybus: battery: move battery file to power_supply
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>
2015-11-12 16:06:49 -08:00