Skip to content

nfc: stop polling before taking the device down on an rfkill block - #71

Merged
derekross merged 1 commit into
derekross:omamobilefrom
W4HO-ham:nfc-rfkill-stop-poll
Oct 31, 2026
Merged

derekross merged 1 commit into
derekross:omamobilefrom
W4HO-ham:nfc-rfkill-stop-poll

Conversation

@W4HO-ham

Copy link
Copy Markdown
Contributor

The shell's NFC tile switches NFC through rfkill, but on the palmtop it did nothing. nfc_rfkill_set_block() calls nfc_dev_down(), and that returns -EBUSY while the device polls or has an active target, which is always with neard running. The error was ignored, so the radio kept polling.

This change deactivates the target and stops the poll first, then takes the device down.

Tested on the palmtop (ST54L on nxp-nci, neard polling): before, rfkill block nfc left about 14 interrupts a second; with this nfc.ko the interrupts stop and nfctool reports the device unpowered. Unblocking and powering it again through neard brings polling back, over three cycles. The userspace side, which tells neard, is omarchy-mobile's omamobile-shell 0.2.29.

checkpatch --strict is clean and core.o builds with W=1.

@derekross

Copy link
Copy Markdown
Owner

Thanks, this is a real bug, and it is the Pixel 7 Pro's bug too. nfc_rfkill_set_block() has ignored nfc_dev_down()'s return since be055b2f89b5 ("NFC: RFKILL support", 2013), and mainline is the same today. On my phone omamobile-nfc-open starts a neard poll loop at boot, so the NFC tile's "Off" has been a no-op here as well; my N2.6 test only covered a block with no poll running.

I read the fix through against the two rfkill fixes already in our 7.3-rc6 base (1ab526d97a57 and d2492688bb9f): no new lock is taken under rfkill_global_mutex beyond the device_lock that nfc_dev_down() already took, the target pointer is only re-checked by index inside nfc_deactivate_target(), and every callee tests shutting_down. In the state with targets found but none selected neither branch fires and the device goes down as before, which is fine. The gate passes on today's branch (sign-off, checkpatch --strict clean, W=1 of core.c), and so does CI.

Two things before I merge it:

  1. It lands after your omarchy-mobile clk: samsung: zumapro: Add the camera clocks #78, once that one is fixed (see my comment there). With this change alone, "Off" works but "On" powers nothing: the kernel does nothing on unblock by design, and neard still believes the adapter is powered, so the tile could turn NFC off and not back on.
  2. After both are in, I'll run one block/unblock cycle on the Pixel 7 Pro, since this is the first time the ST54J's close path runs with a poll active here.

For upstream: Fixes: be055b2f89b5 ("NFC: RFKILL support") and Cc: stable@vger.kernel.org. A maintainer may ask why the deactivate and stop aren't inside nfc_dev_down() for every caller; the answer (neard's own DEV_DOWN wants the -EBUSY so it can stop its poll itself, while rfkill has no one to tell) is worth a sentence in the message. One more for the message: after a kernel-side stop, genl_data.poll_req_portid still names neard; its later STOP_POLL returns -EINVAL at the !dev->polling check and its next START_POLL sets the id again, so nothing breaks, but say so.

And the kernel release (uname -r) you counted the interrupts on, please.

@W4HO-ham
W4HO-ham force-pushed the nfc-rfkill-stop-poll branch from 00ffd49 to cd8588a Compare October 27, 2026 20:40
@W4HO-ham

Copy link
Copy Markdown
Contributor Author

Thanks for reading it against the rfkill fixes. Pushed, rebased on today's omamobile:

  • Fixes: be055b2f89b5 ("NFC: RFKILL support") and Cc: stable@vger.kernel.org.
  • A paragraph on why the stop lives in the rfkill path rather than in nfc_dev_down(): neard's own DEV_DOWN wants the -EBUSY so it can stop its poll itself, while an rfkill block has no one to tell.
  • A paragraph on genl_data.poll_req_portid: after a kernel-side stop it still names neard, its later STOP_POLL returns -EINVAL at the !dev->polling check, and its next START_POLL sets the id again.
  • The test release, 7.3.0-rc6-omamobile-tegu-s2mpg15-m1, whose net/nfc/core.c is this patch's (blob 56a3cf68447c).

checkpatch --strict only notes that it can't see be055b2f89b5, since our tree's base is squashed; it's the 2013 commit in mainline. Understood on the order: this one lands after omarchy-mobile #78.

@derekross

Copy link
Copy Markdown
Owner

Thanks, that's everything I asked for. The code is unchanged (the same net/nfc/core.c as before, which is also the blob you tested), and the message now has the Fixes: and stable tags and the two paragraphs on why the stop sits in the rfkill path and on poll_req_portid. be055b2f89b5 resolves against mainline as expected. The gate passes on today's omamobile (sign-off, checkpatch --strict clean, W=1 of core.c), and so does CI.

One change on my side about the order. Since this afternoon, CONTRIBUTING asks that a change which alters the Pixel 7 Pro on purpose runs on that phone before it merges, not after, and this one does: the tile's "Off" will now close the ST54J with a poll running. So the plan is: I merge your omarchy-mobile #78 first, put this commit on my phone's kernel, run one block/unblock cycle of the tile, and merge this right after if it behaves. Nothing more needed from you.

nfc_rfkill_set_block() calls nfc_dev_down(), which refuses a device that
is polling or has an active target with -EBUSY, and the return value is
ignored. Userspace such as neard keeps a poll loop running whenever the
adapter is powered, so blocking NFC through rfkill left the radio on and
polling.

Deactivate the active target and stop polling first, then take the
device down. This stays in the rfkill path rather than in
nfc_dev_down(): when userspace asks for DEV_DOWN itself, the -EBUSY
tells it to stop its own poll first, while an rfkill block has no one
to tell.

After a stop from here, genl_data.poll_req_portid still names the
process that started the poll. Its later STOP_POLL returns -EINVAL at
the !dev->polling check and its next START_POLL sets the id again, so
nothing breaks.

On a Pixel 9a (ST54L on nxp-nci, 7.3.0-rc6-omamobile-tegu-s2mpg15-m1,
net/nfc/core.c as in this patch) with neard polling, `rfkill block nfc`
left the controller interrupting about 14 times a second; with this
change the interrupts stop and nfctool reports the device unpowered.

Fixes: be055b2f89b5 ("NFC: RFKILL support")
Cc: stable@vger.kernel.org
Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
@derekross

Copy link
Copy Markdown
Owner

A short status, since this has been waiting on me since the 27th. Nothing is needed from you.

The commit is unchanged, and so is the net/nfc/core.c it applies to on today's omamobile. It merges cleanly, and the gate passes (sign-off, checkpatch --strict clean, W=1 of core.c). The shell side (omarchy-mobile #78) has been merged since the 27th. The one thing left is my own run of the NFC tile, Off and then On, with a poll active on my Pixel 7 Pro, as I said on the 27th. My phone is away from the laptop right now, so this comes as soon as it is back on the cable. I'll report back here and merge if it behaves.

For the record, my Pixel 7 Pro NFC series (draft #146) touches the same file, but only nfc_dev_up()'s error path, so the two merge cleanly in either order.

@derekross

Copy link
Copy Markdown
Owner

Ran it on my Pixel 7 Pro tonight (g06ddf519e4bb, this commit on top of #82's test kernel): with a poll active, an rfkill block (what the NFC tile does) now sends RF_DEACTIVATE first (21 06 01 00, answered 41 06 01 00) and only then takes the device down, with no errors; unblock powers it back, neard restarts and discovery resumes. Merging, thank you!

@derekross
derekross merged commit fdfe2b5 into derekross:omamobile Oct 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants