From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796393476; b=U6Ys/Lp27WrATjs5rnKJKK5KtpWWiZXuzGsA9GO3Fa5y2wJa5APRAHyG5KY3rsKksfnt WecU9d2aW1m/GQGnWRM8dc9luxWCXbDPEkiucg+6ElNazDTiII76/unmAGWgbKws/ROk/ l457I3hgbMqhJJOfWZWsx/I7KX9wCk1s2xqWONiCmXOj4hftObXamC+FjMsvQcm7viVqw x0A2iUyooStlnFGgK/rqin5jCQagBwao7yrXLX1NmpWIDqNXVBu9dJ0Cj8gPrnqMsYvFi 8Ktqb7JyISh5VVUXKUyH/+nNv7TpSFrpau+jAUNs99KE20f6ZtLj20QPzd9gr2l2WGA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796393476; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=g6I7+fIExs/yFebSc+cRQQRJayAPKykfPnM7EdR+QnA=; b=ta7L77iWos+fkzg6RuPFVY9QYQHGDyXzQ0wU+5KdNKFQHdCv8Ee0hMbqREBbU5lR2oNX gZExc2tYv8yVW+J+xxcB3Jmy/8UwDgrbPCuu1BrPSrV1rWFPvMqn2Y8CCem/3foKn65tE HzVRDNXjMM/Li99DoX0gRnDffu+yTcqz6InMZ/Ku0pmnTzWrJNtjPCaUTf/fHdn3ypNRh IddAUB6gRMHwo+urWHLtNC3gRk793OCs08mDNwbZ+tEKflY9lrenszjpxyyCgF6cw/7wO woXAG/tGWA/c8S5arDNU9Un5YRra0SqDEAKJgCFxzugDvVWD4VZiDiiESaKBd8Bb/JA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Z5uFGl/o"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76EA0606A333; Fri, 4 Dec 2026 14:11:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Z5uFGl/o Received: by smtp.kernel.org (Postfix) with ESMTPSA id 633901F00937; Fri, 4 Dec 2026 14:11:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796393476; bh=g6I7+fIExs/yFebSc+cRQQRJayAPKykfPnM7EdR+QnA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Z5uFGl/oebPyGzBs44UBa0RBQPOVjjH9sZFa2lQLw0DObQcnMDvoEE7ZZWahzTfS7 1NBKvRfM97uTLIGMkjK6mABzgz57OOSk1qO2ZiIwb0CBDExBLleay/uPgRScpzCVBs wLfnErLUOLcARJ2buXDafmUGGE1V+dNVVKp4Ca8IEGXYj25PqW/1IndwnwgyqU7sUN VIZuW0g2COyXCfd5Zb7LHxMZ+ZlCzkzFn2CMh9zJjT+hS+LOevhhmQDKeOxJ04vXep w6T6WDxWWUhSzN8mIfvOaiQFJZD65zTL747rbNnpoQHL3KudLJpiZ6srHkUau3qY3c QDDeSKNmAVpUA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 05/14] iio/accel: add driver for apple SMS Reply-To: sashiko-reviews@lists.linux.dev To: "Atharva Tiwari" Cc: "Ihor Odainyi" , "Bjorn Helgaas" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , x86@kernel.org, "H. Peter Anvin" , "Rafael J. Wysocki" , "Len Brown" , "Linus Walleij" , "Bartosz Golaszewski" , "Sven Peter" , "Janne Grunau" , "Neal Gompa" , "Guenter Roeck" , "Jonathan Cameron" , "David Lechner" , =?utf-8?b?TnVubyBTw6E=?= , "Andy Shevchenko" , "Lee Jones" , "Pavel Machek" , "Griffin Kroah-Hartman" , "Hans de Goede" , =?utf-8?b?SWxwbyBKw6RydmluZW4=?= , "Sebastian Reichel" , "Alexandre Belloni" , "Wim Van Sebroeck" , "Jarkko Sakkinen" , "Mimi Zohar" , "Roberto Sassu" , "Dmitry Kasatkin" , "Eric Snowberg" , "Paul Moore" , "James Morris" , "Serge E. Hallyn" , linux-pci@vger.kernel.org, linux-gpio@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-leds@vger.kernel.org, mfd@lists.linux.dev, linux-rtc@vger.kernel.org, linux-watchdog@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org In-Reply-To: <20261204131619.5059-6-atharvatiwarilinuxdev@gmail.com> References: <20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com> <20261204131619.5059-6-atharvatiwarilinuxdev@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 14:11:10 +0000 X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 7 potential issues to consider: - [Medium] iio: accel: macsmc-accel: missing event config callbacks in macsmc_accel_info - [Medium] iio: accel: macsmc_accel_probe() enables notifier before IIO registration - [Medium] iio: accel: macsmc_accel_dev_init() ignores SMC errors and misorders poll - [Medium] iio: accel: macsmc-accel: undocumented orientation change event ABI - [Medium] mfd: macsmc: probing absent MOCN via apple_smc_key_exists() stalls PIO boot - [Low] iio: accel: macsmc-accel: s16 passed to be16_to_cpu() in macsmc_accel_read() - [Low] iio: accel: macsmc-accel: Makefile order, MFD cell ID, and subject conventions -- commit 72edf11305348abc7eba7049f44352095cfc9e6d Author: Atharva Tiwari iio/accel: add driver for apple SMS This commit adds an IIO accelerometer driver for the Apple SMC Sudden Motion Sensor (reporting X/Y/Z axes and drop, orientation, and shock events) and registers it from the ACPI SMC MFD core when the MOCN key exists. > diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile > index fa440a8592839..52fe661dec666 100644 > --- a/drivers/iio/accel/Makefile > +++ b/drivers/iio/accel/Makefile > @@ -54,6 +54,7 @@ obj-$(CONFIG_KXSD9) +=3D kxsd9.o > obj-$(CONFIG_KXSD9_SPI) +=3D kxsd9-spi.o > obj-$(CONFIG_KXSD9_I2C) +=3D kxsd9-i2c.o > obj-$(CONFIG_MC3230) +=3D mc3230.o > +obj-$(CONFIG_MACSMC_ACCEL) +=3D macsmc-accel.o [Severity: Low] This isn't a bug, but CONFIG_MACSMC_ACCEL is placed after CONFIG_MC3230, breaking the alphabetical ordering in this Makefile. Similarly, the new devm_mfd_add_devices() call in drivers/mfd/macsmc-core.c passes -1 instead of PLATFORM_DEVID_AUTO (or PLATFORM_DEVID_NONE), and the commit subject uses "iio/accel:" instead of the standard "iio: accel:" prefix. > diff --git a/drivers/iio/accel/macsmc-accel.c b/drivers/iio/accel/macsmc-= accel.c > new file mode 100644 > index 0000000000000..79891fd13c56a > --- /dev/null > +++ b/drivers/iio/accel/macsmc-accel.c [ ... ] > +static int macsmc_accel_read(struct macsmc_accel *drv, smc_key key, s16 = *p) > +{ > + int ret; > + > + ret =3D apple_smc_read_s16(drv->smc, key, p); > + if (ret < 0) > + return ret; > + > + *p =3D (s16)be16_to_cpu(*p); > + return 0; > +} [Severity: Low] Does passing host-endian s16 *p directly to be16_to_cpu() trigger a sparse endianness warning? __be16_to_cpu() expects a restricted __be16 value, so reading into a local __be16 (e.g., via apple_smc_read()) and converting with be16_to_cpu() into *p keeps the endianness types sparse-clean. > +static int macsmc_accel_dev_init(struct macsmc_accel *drv) > +{ > + int ret, total; > + u16 buf, write_value; > + > + ret =3D apple_smc_read_u16(drv->smc, SMC_KEY(MOCN), &buf); > + if (ret < 0) > + return ret; > + > + /* 0xE0 enables the interrupts and the actual motion sensors */ > + write_value =3D buf | 0xE0; > + > + for (total =3D 0; total < 100; total++) { > + ret =3D apple_smc_read_u16(drv->smc, SMC_KEY(MOCN), &buf); > + if (!ret && (buf & 0xE0) =3D=3D 0xE0) > + return 0; > + > + apple_smc_write_u16(drv->smc, SMC_KEY(MOCN), write_value); > + msleep(50); > + } > + > + return -ENODEV; > +} [Severity: Medium] Can this retry loop stall probe or hibernation restore for minutes while holding smc->mutex? Both read errors from apple_smc_read_u16() and the return value of apple_smc_write_u16() are ignored across 100 iterations. Each SMC transaction holds smc->mutex and can wait up to SMC_TIMEOUT_MS (1000 ms), turning persistent timeouts into a multi-minute stall for sibling drivers. The loop also re-reads MOCN on iteration 0 without checking the initial read for (buf & 0xE0) =3D=3D 0xE0, and returns -ENODEV after the 100th write and sleep without checking whether that final write took effect. Checking the initial read, propagating I/O errors (or bounding wall-clock time), and doing write, sleep, then read in the loop avoids these issues. [ ... ] > + case SMC_INT_SMS_ORIENTATION: > + code =3D IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_X_OR_Y_OR_Z, > + IIO_EV_TYPE_CHANGE, IIO_EV_DIR_NONE); > + break; [Severity: Medium] As reported by Jonathan Cameron on RFC [1], what acceleration condition triggers SMC_INT_SMS_ORIENTATION? No other IIO_ACCEL driver uses IIO_EV_TYPE_CHANGE, and in_accel_x|y|z_change_en is undocumented in Documentation/ABI/testing/sysfs-bus-iio, so userspace cannot interpret it. [ ... ] > +static const struct iio_event_spec macsmc_accel_drop_events[] =3D { > + { > + .type =3D IIO_EV_TYPE_THRESH, > + .dir =3D IIO_EV_DIR_FALLING, > + .mask_separate =3D BIT(IIO_EV_INFO_ENABLE), > + }, > +}; > + > +static const struct iio_event_spec macsmc_accel_any_axis_events[] =3D { > + { > + .type =3D IIO_EV_TYPE_THRESH, > + .dir =3D IIO_EV_DIR_RISING, > + .mask_separate =3D BIT(IIO_EV_INFO_ENABLE), > + }, > + { > + .type =3D IIO_EV_TYPE_CHANGE, > + .dir =3D IIO_EV_DIR_NONE, > + .mask_separate =3D BIT(IIO_EV_INFO_ENABLE), > + }, > +}; [ ... ] > +static const struct iio_info macsmc_accel_info =3D { > + .read_raw =3D macsmc_accel_read_raw > +}; [Severity: Medium] Will all three exported *_en event sysfs attributes unconditionally fail with -EINVAL? Setting BIT(IIO_EV_INFO_ENABLE) registers the *_en attributes via iio_ev_state_show() and iio_ev_state_store(), which both return -EINVAL when read_event_config and write_event_config are NULL in macsmc_accel_info. This either needs those callbacks implemented or BIT(IIO_EV_INFO_ENABLE) omitted if the events are always enabled. [ ... ] > + ret =3D macsmc_accel_dev_init(drv); > + if (ret) > + return ret; > + > + drv->indio_dev =3D indio_dev; > + drv->nb.notifier_call =3D macsmc_accel_event; > + ret =3D blocking_notifier_chain_register(drv->smc->event_handlers, &drv= ->nb); > + if (ret) > + return ret; > + > + ret =3D devm_add_action_or_reset(&pdev->dev, macsmc_accel_unregister_no= tifier, drv); > + if (ret) > + return ret; > + > + platform_set_drvdata(pdev, drv); > + > + indio_dev->name =3D "macsmc-accel"; > + indio_dev->modes =3D INDIO_DIRECT_MODE; > + indio_dev->info =3D &macsmc_accel_info; > + indio_dev->channels =3D macsmc_accel_channels; > + indio_dev->num_channels =3D ARRAY_SIZE(macsmc_accel_channels); > + > + return devm_iio_device_register(&pdev->dev, indio_dev); > +} [Severity: Medium] Can macsmc_accel_event() hit a use-after-free on ev_int if devm_iio_device_register() fails? The parent SMC IRQ and notifier work are already active before macsmc_accel_probe() runs, and macsmc_accel_dev_init() enables motion sensor interrupts before the IIO device is registered. If a late step in __iio_device_register() fails, it frees ev_int before devres unregisters the notifier: CPU0 CPU1 (kworker) macsmc_accel_probe() macsmc_accel_dev_init() blocking_notifier_chain_register() devm_iio_device_register() iio_device_register_eventset() iio_dev_opaque->event_interface =3D ev_int apple_smc_acpi_notifier_work() macsmc_accel_event() iio_push_event() ev_int =3D ...->event_interface ... (error unwind) kfree(ev_int) iio_dev_opaque->event_interface =3D NULL iio_event_enabled(ev_int) <-- use-after-free If the freed slab object is reused with its enabled bit set, kfifo_put() and wake_up_poll() can also corrupt memory. Registering the IIO device before registering the SMC notifier closes this window and ensures the notifier is torn down before iio_device_unregister() on remove. > diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c > index 6014df4fe1c0a..6567d2f1f8f53 100644 > --- a/drivers/mfd/macsmc-core.c > +++ b/drivers/mfd/macsmc-core.c [ ... ] > @@ -169,6 +173,12 @@ int apple_smc_probe(struct device *dev, const struct= apple_smc_backend_ops *ops, > return ret; > } > =20 > + if (apple_smc_key_exists(smc, SMC_KEY(MOCN))) { > + ret =3D devm_mfd_add_devices(dev, -1, apple_smc_acpi_accel, > + ARRAY_SIZE(apple_smc_acpi_accel), NULL, 0, NULL); > + if (ret < 0) > + return ret; > + } > } else > ret =3D devm_mfd_add_devices(dev, -1, apple_smc_rtkit_devs, > ARRAY_SIZE(apple_smc_rtkit_devs), NULL, 0, NULL); [Severity: Medium] Does probing SMC_KEY(MOCN) via apple_smc_key_exists() add a 1-second synchronous boot stall on PIO-based Intel Macs without a motion sensor? On PIO Macs, apple_smc_acpi_port_get_key_info() has no non-timeout error check, so an absent key only fails after apple_smc_acpi_port_wait() polls SMC_IO_CMD_PORT for the full SMC_TIMEOUT_MS (1000 ms). Binary searching via GET_KEY_BY_INDEX (like applesmc_has_key()) avoids this timeout. [1] https://lore.kernel.org/r/20261101013540.3af16ea0@jic23-hlaptop --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204131619.5059= -1-atharvatiwarilinuxdev@gmail.com?part=3D5