summaryrefslogtreecommitdiff
path: root/drivers/staging/greybus/light.c
AgeCommit message (Collapse)Author
2020-01-29staging: greybus: light: fix a couple double freesDan Carpenter
[ Upstream commit 329101244f214952606359d254ae883b7109e1a5 ] The problem is in gb_lights_request_handler(). If we get a request to change the config then we release the light with gb_lights_light_release() and re-allocated it. However, if the allocation fails part way through then we call gb_lights_light_release() again. This can lead to a couple different double frees where we haven't cleared out the original values: gb_lights_light_v4l2_unregister(light); ... kfree(light->channels); kfree(light->name); I also made a small change to how we set "light->channels_count = 0;". The original code handled this part fine and did not cause a use after free but it was sort of complicated to read. Fixes: 2870b52bae4c ("greybus: lights: add lights implementation") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Acked-by: Rui Miguel Silva <rmfrfs@gmail.com> Link: https://lore.kernel.org/r/20190829122839.GA20116@mwanda Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
2017-12-25staging: greybus: light: Release memory obtained by kasprintfArvind Yadav
[ Upstream commit 04820da21050b35eed68aa046115d810163ead0c ] Free memory region, if gb_lights_channel_config is not successful. Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com> Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-10-02staging: greybus: light: check the correct value of delay_onRui Miguel Silva
When checking the value of delay_on to set the channel as active, it was checked the pointer and not the value, as it should be. Fixes: cc43368a3c ("greybus: lights: Control runtime pm suspend/resume on AP side") Signed-off-by: Rui Miguel Silva <rmfrfs@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-10-02staging: greybus: light: check delay_{on|off} before useRui Miguel Silva
Even though we trust leds core that the pointers should be valid, we are safer to check delay_{on|off} before use. Also, this avoid a smatch warning: drivers/staging/greybus/light.c:484 gb_blink_set() warn: variable dereferenced before check 'delay_on' (see line 476) Signed-off-by: Rui Miguel Silva <rmfrfs@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-10-02staging: greybus: light: fix attributes allocationRui Miguel Silva
Fix allocation of attributes with the correct size, this also fix smatch warning: drivers/staging/greybus/light.c:293 channel_attr_groups_set() warn: double check that we're allocating correct size: 8 vs 16 Signed-off-by: Rui Miguel Silva <rmfrfs@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-09-19staging: greybus: light: remove KERNEL_VERSION checksRui Miguel Silva
No need to support older kernel versions in the Greybus Light driver, so remove the checks as needed, we can now rely on all of the correct LED core apis being present. And compile only if flash and v4l2 flash is reachable. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-08-26greybus: lights: Control runtime pm suspend/resume on AP sideKris Huang
According to runtime pm architecture, the kernel side driver should be as smart as needed to know when the module is idle or active, so that it can issue the suspend/resume operations to the firmware side at the right time. To add logics prevents AP from issuing the suspend request to the firmware when a channel turning to active state, and put it to suspend if the state is going to inactive with still holding a reference. Testing Done: Compiled and verified on EVT2 and gpbridge-test module with device class daughter board. Signed-off-by: Kris Huang <huang_kris@projectara.com> Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-08-26greybus: light: fix incorrect led attribute files allocationDavid Lin
Fix incorrect attribute size when the channel supports fader, as well as fixing the issue that the attribute list is not null terminated. Testing Done: - Verified by setting brightness and color on red/green/blue leds of the device class test board. Signed-off-by: David Lin <dtwlin@google.com> Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-08-10greybus: lights: enable multi color LED supportKris Huang
A backport (commit 79c4de08c0e5a26b04a4ac9e6543dad6379f0b40) was applied in kernel which adding attribute-group support in led-class. Remove the LED_HAVE_GROUPS flag check entirely that allow led drivers to create custom attributes like color/fade_in/fade_out. Testing Done: Compiled and verified on EVT2 and gpbridge-test module with device class daughter board. Signed-off-by: Kris Huang <huang_kris@projectara.com> Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-08-05greybus: lights: Add runtime pm supportKris Huang
Modify Lights greybus driver to support runtime PM framework. The suspend and resume function have been tested with gpbridge-test image by sysfs. Lights functions work well on suspend/resume. Testing Done: Compiled and verified on EVT2 and gpbridge-test module with device class daughter board. Signed-off-by: Kris Huang <huang_kris@projectara.com> Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-29greybus: light: Initialize mutex before using itViresh Kumar
Light protocol driver is suffering from the same issue that was fixed in camera driver earlier (commit a7c3b0c3c8da). Big cleanup function is used instead of fine grained control in the error path, and in one of the cases the mutex was found uninitialized and so the oops seen in SW-6752. Initialize the mutex before any code can access it. Compile tested only. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-27greybus: fix pointless null checkAlex Elder
Coccinelle points out that a call in gb_lights_channel_free() to flush_work() is passed which is always non-null. Prior to the call, there is an unnecessary check to see if that address is null. Get rid of the test. 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-03-22greybus: convert drivers to use connection->private set/getGreg Kroah-Hartman
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-02-25greybus: lights: remove unnecessary checkRui Miguel Silva
lights can never be NULL at that point since lights_count must be different than zero, and we need only to validate the light_id. Reported-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-02-17greybus: lights: fix check for configured lightsRui Miguel Silva
The validation for a complete configured light is wrong and it is reworked to make sure that only when the light is ready, will handle request events. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Reported-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-02-17greybus: lights: remove has_flash on failureRui Miguel Silva
If register to v4l2 fails just mark the light as not having flash so in release we do not try to unregister. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-02-17greybus: lights: remove unnecessary checksRui Miguel Silva
We do not need to check for channels and lights as they can never be NULL as a big memory array elements. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Reported-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-02-15greybus: lights: convert to bundle driverViresh Kumar
Convert the legacy lights 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-15greybus: lights: Break light setup into two partsViresh Kumar
This breaks the light setup routine into two parts, the first one allocates all the necessary resources and the second on registers lights 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-01-13greybus: lights: remove sync operation and work queueRui Miguel Silva
In kernel v4.5 there is a change in LED api, which remove the need for individual work queue and rename the set_sync operation to set_blocking. This patch add the handling of this case and avoid compilation failure for this kernel versions. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-12-03greybus: lights: default value for v4l2 flash controlsRui Miguel Silva
V4l2 flash will return erro ERANGE if val(which is the default value) is not defined. Just set it to the max value reported by the module. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-12-03greybus: lights: avoid channel torch double freeRui Miguel Silva
When attaching torch to a flash we release the channel torch resources, but afterwards we do it again when releasing all the channels. Just free all the resource at channel release. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-12-03greybus: lights: add v4l2 flash operationsRui Miguel Silva
We do not implement any of the v4l2 flash operations, as the default ones are ok for now, however the init needs anything define, if not it will return an error. So, just define it and have an error free v4l2 flash init. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-11-11greybus: light: fix class-device parentJohan Hovold
Greybus bundle drivers should register their class devices as children to the bundle device that they bind to. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-10-15greybus: light : use the bundle struct device instead of the connectorGreg Kroah-Hartman
We are removing struct device from the gb_connection structure in the near future. The gb_bundle structure's struct device should be used as a replacement. This patch moves the light driver to use the bundle pointer instead of the connection pointer. Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Reviewed-by: Alex Elder <elder@linaro.org>
2015-08-14greybus: lights: add lights implementationRui Miguel Silva
This patch adds lights implementation for Greybus Lights class, it allows multiplexing of lights devices using the same connection. Also adds two sysfs entries to led class (color, fade) which are commonly used in several existing LED devices. It support 2 major class of devices (normal LED and flash type), for the first it registers to led_classdev, for the latest it registers in the led_classdev_flash and v4l2_flash, depending on the support of the kernel version. Each Module can have N light devices attach and each light can have multiple channel associated: glights |->light0 | |->channel0 | |->channel1 | | .... | |->channeln |->... |->lightn |->channel0 |->channel1 | .... |->channeln Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>