History log of /linux-master/drivers/nfc/nfcmrvl/main.c
Revision Date Author Comments
# cc6d85c1 14-Mar-2023 Rob Herring <robh@kernel.org>

nfc: mrvl: Use of_property_read_bool() for boolean properties

It is preferred to use typed property access functions (i.e.
of_property_read_<type> functions) rather than low-level
of_get_property/of_find_property functions for reading properties.
Convert reading boolean properties to of_property_read_bool().

Reviewed-by: Simon Horman <simon.horman@corigine.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>


# d270453a 29-Apr-2022 Duoming Zhou <duoming@zju.edu.cn>

nfc: nfcmrvl: main: reorder destructive operations in nfcmrvl_nci_unregister_dev to avoid bugs

There are destructive operations such as nfcmrvl_fw_dnld_abort and
gpio_free in nfcmrvl_nci_unregister_dev. The resources such as firmware,
gpio and so on could be destructed while the upper layer functions such as
nfcmrvl_fw_dnld_start and nfcmrvl_nci_recv_frame is executing, which leads
to double-free, use-after-free and null-ptr-deref bugs.

There are three situations that could lead to double-free bugs.

The first situation is shown below:

(Thread 1) | (Thread 2)
nfcmrvl_fw_dnld_start |
... | nfcmrvl_nci_unregister_dev
release_firmware() | nfcmrvl_fw_dnld_abort
kfree(fw) //(1) | fw_dnld_over
| release_firmware
... | kfree(fw) //(2)
| ...

The second situation is shown below:

(Thread 1) | (Thread 2)
nfcmrvl_fw_dnld_start |
... |
mod_timer |
(wait a time) |
fw_dnld_timeout | nfcmrvl_nci_unregister_dev
fw_dnld_over | nfcmrvl_fw_dnld_abort
release_firmware | fw_dnld_over
kfree(fw) //(1) | release_firmware
... | kfree(fw) //(2)

The third situation is shown below:

(Thread 1) | (Thread 2)
nfcmrvl_nci_recv_frame |
if(..->fw_download_in_progress)|
nfcmrvl_fw_dnld_recv_frame |
queue_work |
|
fw_dnld_rx_work | nfcmrvl_nci_unregister_dev
fw_dnld_over | nfcmrvl_fw_dnld_abort
release_firmware | fw_dnld_over
kfree(fw) //(1) | release_firmware
| kfree(fw) //(2)

The firmware struct is deallocated in position (1) and deallocated
in position (2) again.

The crash trace triggered by POC is like below:

BUG: KASAN: double-free or invalid-free in fw_dnld_over
Call Trace:
kfree
fw_dnld_over
nfcmrvl_nci_unregister_dev
nci_uart_tty_close
tty_ldisc_kill
tty_ldisc_hangup
__tty_hangup.part.0
tty_release
...

What's more, there are also use-after-free and null-ptr-deref bugs
in nfcmrvl_fw_dnld_start. If we deallocate firmware struct, gpio or
set null to the members of priv->fw_dnld in nfcmrvl_nci_unregister_dev,
then, we dereference firmware, gpio or the members of priv->fw_dnld in
nfcmrvl_fw_dnld_start, the UAF or NPD bugs will happen.

This patch reorders destructive operations after nci_unregister_device
in order to synchronize between cleanup routine and firmware download
routine.

The nci_unregister_device is well synchronized. If the device is
detaching, the firmware download routine will goto error. If firmware
download routine is executing, nci_unregister_device will wait until
firmware download routine is finished.

Fixes: 3194c6870158 ("NFC: nfcmrvl: add firmware download support")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Signed-off-by: David S. Miller <davem@davemloft.net>


# 26955037 28-Jul-2021 Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>

nfc: mrvl: constify static nfcmrvl_if_ops

File-scope struct nfcmrvl_if_ops is not modified so can be made const.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>


# fe53159f 28-Jul-2021 Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>

nfc: mrvl: constify several pointers

Several functions do not modify pointed data so arguments and local
variables can be const for correctness and safety.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>


# b9c28286 24-Jul-2021 Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>

nfc: constify nci_ops

The struct nci_ops is modified by NFC core in only one case:
nci_allocate_device() receives too many proprietary commands (prop_ops)
to configure. This is a build time known constrain, so a graceful
handling of such case is not necessary.

Instead, fail the nci_allocate_device() and add BUILD_BUG_ON() to places
which set these.

This allows to constify the struct nci_ops (consisting of function
pointers) for correctness and safety.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>


# be3d162a 31-May-2021 Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>

nfc: mrvl: use SPDX-License-Identifier

Use SPDX-License-Identifier: GPL-2.0-only, instead of hand writing it.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Link: https://lore.kernel.org/r/20210531073522.6720-3-krzysztof.kozlowski@canonical.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>


# c3953a3c 04-Aug-2019 Johan Hovold <johan@kernel.org>

NFC: nfcmrvl: fix gpio-handling regression

Fix two reset-gpio sanity checks which were never converted to use
gpio_is_valid(), and make sure to use -EINVAL to indicate a missing
reset line also for the UART-driver module parameter and for the USB
driver.

This specifically prevents the UART and USB drivers from incidentally
trying to request and use gpio 0, and also avoids triggering a WARN() in
gpio_to_desc() during probe when no valid reset line has been specified.

Fixes: e33a3f84f88f ("NFC: nfcmrvl: allow gpio 0 for reset signalling")
Reported-by: syzbot+cf35b76f35e068a1107f@syzkaller.appspotmail.com
Tested-by: syzbot+cf35b76f35e068a1107f@syzkaller.appspotmail.com
Signed-off-by: Johan Hovold <johan@kernel.org>


# e33a3f84 29-Mar-2017 Johan Hovold <johan@kernel.org>

NFC: nfcmrvl: allow gpio 0 for reset signalling

Allow gpio 0 to be used for reset signalling, and instead use negative
errnos to disable the reset functionality.

Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# 45dd39b9 29-Mar-2017 Johan Hovold <johan@kernel.org>

NFC: nfcmrvl: fix firmware-management initialisation

The nci-device was never deregistered in the event that
fw-initialisation failed.

Fix this by moving the firmware initialisation before device
registration since the firmware work queue should be available before
registering.

Note that this depends on a recent fix that moved device-name
initialisation back to to nci_allocate_device() as the
firmware-workqueue name is now derived from the nfc-device name.

Fixes: 3194c6870158 ("NFC: nfcmrvl: add firmware download support")
Cc: stable <stable@vger.kernel.org> # 4.4
Cc: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# 0cbe4011 29-Mar-2017 Johan Hovold <johan@kernel.org>

NFC: nfcmrvl: do not use device-managed resources

This specifically fixes resource leaks in the registration error paths.

Device-managed resources is a bad fit for this driver as devices can be
registered from the n_nci line discipline. Firstly, a tty may not even
have a corresponding device (should it be part of a Unix98 pty)
something which would lead to a NULL-pointer dereference when
registering resources.

Secondly, if the tty has a class device, its lifetime exceeds that of
the line discipline, which means that resources would leak every time
the line discipline is closed (or if registration fails).

Currently, the devres interface was only being used to request a reset
gpio despite the fact that it was already explicitly freed in
nfcmrvl_nci_unregister_dev() (along with the private data), something
which also prevented the resource leak at close.

Note that the driver treats gpio number 0 as invalid despite it being
perfectly valid. This will be addressed in a follow-up patch.

Fixes: b2fe288eac72 ("NFC: nfcmrvl: free reset gpio")
Fixes: 4a2b947f56b3 ("NFC: nfcmrvl: add chip reset management")
Cc: stable <stable@vger.kernel.org> # 4.2: b2fe288eac72
Cc: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# d58ff351 16-Jun-2017 Johannes Berg <johannes.berg@intel.com>

networking: make skb_push & __skb_push return void pointers

It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.

Make these functions return void * and remove all the casts across
the tree, adding a (u8 *) cast only where the unsigned char pointer
was used directly, all done with the following spatch:

@@
expression SKB, LEN;
typedef u8;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)

@@
expression E, SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)

@@
expression SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- fn(SKB, LEN)[0]
+ *(u8 *)fn(SKB, LEN)

Note that the last part there converts from push(...)[0] to the
more idiomatic *(u8 *)push(...).

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>


# 6f8c5369 03-Nov-2015 Vincent Cuissard <cuissard@marvell.com>

NFC: nfcmrvl: remove unneeded CONFIG_OF switches

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# b2fe288e 03-Nov-2015 Vincent Cuissard <cuissard@marvell.com>

NFC: nfcmrvl: free reset gpio

Reset GPIO shall be freed by the driver since the device used
in devm_ calls can be still valid on unregister.

If user removes the module and inserts it again, the devm_gpio_request
will fail because the underlying physical device (e.g i2c) was not
removed so the device management won't have freed the gpio.

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# caf6e49b 26-Oct-2015 Vincent Cuissard <cuissard@marvell.com>

NFC: nfcmrvl: add spi driver

This driver adds the support of SPI-based Marvell NFC controller.

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# b5b3e23e 26-Oct-2015 Vincent Cuissard <cuissard@marvell.com>

NFC: nfcmrvl: add i2c driver

This driver adds the support of I2C-based Marvell NFC controller.

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# 58d34aa6 26-Oct-2015 Vincent Cuissard <cuissard@marvell.com>

NFC: nfcmrvl: configure head/tail room values per low level drivers

Low-level drivers may need to add some data before and/or
after NCI packet.

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# 3194c687 26-Oct-2015 Vincent Cuissard <cuissard@marvell.com>

NFC: nfcmrvl: add firmware download support

Implement firmware download protocol for Marvell NFC controllers.
This protocol is based on NCI frames that's why parts of its
implementation use some NCI generic functions.

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# fb101c0e 26-Oct-2015 Vincent Cuissard <cuissard@marvell.com>

NFC: nfcmrvl: remove unneeded version defines

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# d0dcad8b 12-Jun-2015 Vincent Cuissard <cuissard@marvell.com>

NFC: nfcmrvl: set PB_BAIL_OUT at setup

PB_BAIL_OUT parameter as to be set to one. This is needed because
digital protocol 1.0 is used in combination with ISO15693 protocol.

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# 83d56725 12-Jun-2015 Vincent Cuissard <cuissard@marvell.com>

NFC: nfcmrvl: Allow ISO15693 protocol

Reference Marvell NFC controller as ISO15693 capable.

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# dc14bdef 11-Jun-2015 Vincent Cuissard <cuissard@marvell.com>

NFC: nfcmrvl: add platform_data and DT configuration

Declare nfcmrvl platform_data structure and few DT parameters
for nfcmrvl driver.

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# 4a2b947f 11-Jun-2015 Vincent Cuissard <cuissard@marvell.com>

NFC: nfcmrvl: add chip reset management

Low level driver can specify a GPIO that will be used to reset
the chip. Thanks to this the driver can ensure the state of the
device at init.

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# e1bf80c2 11-Jun-2015 Vincent Cuissard <cuissard@marvell.com>

NFC: nfcmrvl: update nci recv frame API

Update internal nci recv frame API to use skbuff phy management
to generic part of the driver.

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# f1f1a7da 11-Jun-2015 Vincent Cuissard <cuissard@marvell.com>

NFC: nfcmrvl: add support of HCI-based transport

In some configuration NCI packet can be encapsulated in HCI
packets. This patch had the support of this.

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# d18ee5a5 11-Jun-2015 Vincent Cuissard <cuissard@marvell.com>

NFC: nfcmrvl: remove integration related settings

These settings are related to a specific integration that requires
the firmware to drive some GPIOs for external RF coexistency.

Since this is really linked to specific hardware integration let's
remove them.

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# 3590ebc0 07-Apr-2015 Joe Perches <joe@perches.com>

NFC: logging neatening

Add missing terminating newlines to nfc_info and nfc_err
to avoid possible interleaving from other messages.

Miscellanea:

o typo fix of "unknonwn" in message
o remove unnecessary OOM messages as there's a generic dump_stack()
o realign arguments

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# bb55dc2a 08-Jan-2014 Amitkumar Karwar <akarwar@marvell.com>

NFC: nfcmrvl: Fix possible memory leak issue

This patch fixes memory leaks in the error paths of
nfcmrvl_nci_register_dev() routine.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Amitkumar Karwar <akarwar@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# 15203b4c 06-Jan-2014 Amitkumar Karwar <akarwar@marvell.com>

NFC: nfcmrvl: Add setup handler

Marvell nfc device provides support for external coexistance
control. It allows Device Host to inhibit the NFCC from polling
when required by asserting a GPIO pin. A second pin allows the
DH to have feedback on the current NFCC state.

The required configuration for this feature is done in setup
handler.

Signed-off-by: Amitkumar Karwar <akarwar@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# f26e30cc 06-Jan-2014 Amitkumar Karwar <akarwar@marvell.com>

NFC: nfcmrvl: Initial commit for Marvell NFC driver

This patch adds NFC support for Marvell 8897 NFC-over-USB chipset.

Signed-off-by: Amitkumar Karwar <akarwar@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>