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=1796392025; b=ywVREVicA4WqPkg8p0vSrnv5MxJpWl29jw/axKR2V7FvLy/Wc9eN3xAHxwm67ecMqslz cJwt5+qF7+AVVZdpXeSQEGepybipTw2XdS8JvVtCZn7O0IMF0reW0KqpLAE/4Y6Yq4rLY RFRKd6c4IlZVZC9bJM//yIq9v145b9GTxRHIrHCvY7v5ntiwhK2pkgVDTyGdi0DUM21C8 RrihYIMPXKOXtTvvkYlQtfhu4BvvkXTmqPEEEoe2nZbmP1xQ3A8xvrqw3nFo+JGP+ynUd dI6gzIZxqHjKe9bmb9i9xUmvQpRbInlX9csfucO3Ly/pPLZViWfUQ809eEjHhTbJL6g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796392025; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=jSk0ycLREsj78qYSIQjroH+2EfDHVXKdwoLTlJr1cnQ=; b=cFvQvZV5yBoFmXD/nrXmqkF0Nik3SUYkiqH5d17lOOCep3mA9Z+xGFv7UQmomg1OkhL+ 30CtV2vgxDlXf/I6eZdZzU1QNhP+FbHUrnp5sRrZmq44TfW7XDuaMo+wMFIaW+KHfBJuf iFcYN0dF9pAktMQBdfAfEckrSvIOVY+8bznJ7B/Z6QX3TA55vfIWA8tkHSa28sYzdFuSr MwfqqRRI5rDzVluvTibg76kv4IU1SNtohuXe6EH8Ge5vO7cHnjt24eiyGu/livUvjA3d+ B4xrFMVQcJYf2cA+JuqWnb222RTfDfAtajp0B2yhGAf8HlKkvgW0DTKMi+7G1poXHOw== 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=ChdIr8yE; 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 B39F9606A322; Fri, 4 Dec 2026 13:47:05 +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=ChdIr8yE Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93EB61F000CE; Fri, 4 Dec 2026 13:47:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796392025; bh=jSk0ycLREsj78qYSIQjroH+2EfDHVXKdwoLTlJr1cnQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ChdIr8yEhdwQfLVVTnY8T2jTtdgQ5zWCcfX6f6gbvev8PGleEJcESKuEO1KFDIgza kSi7fnTU1+Kt2Vq3gZK4cZ5rB65BBBKvN6QHWwFnhOrBf35U31BdJ+47mwrKKtIReo yuHTde4gvdzpgus4O73UOWQZRq+OBg3oqlGBhQ5+MyFZM8CfIathQUjCDWlC0qNaYy GbP1JoTqUMGrNXXiXx1BIQlsESkxd9lzd7Ae8JOEs3Ay8D/MCATlcd3ckvytOYLks9 r8ByOfsOK4J5V8GKsj92wavfZalAXfOiU1lH3PaNW5//PBmbL8rXr3Dc5/2he5mmo1 gDMiOkcj+DFzA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 04/14] iio/light: add new driver for macsmc Reply-To: sashiko-reviews@lists.linux.dev To: "Atharva Tiwari" Cc: "Ihor Odainyi" , "Antoine Sidem" , "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-5-atharvatiwarilinuxdev@gmail.com> References: <20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com> <20261204131619.5059-5-atharvatiwarilinuxdev@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 13:47:03 +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 5 potential issues to consider: - [Medium] iio: light: notifier registered before devm_iio_device_register() causes UAF - [Medium] iio: light: unconditional RIGHT_LIGHT channel and missing ALV1 validation - [Medium] iio: light: macsmc-light exposes unitless raw SMC counts as IIO_LIGHT - [Low] iio: light: Kconfig module name mismatch and MACSMC_ACPI dependency - [Low] mfd: macsmc: literal -1 passed to devm_mfd_add_devices() for light cell -- commit e9ed4cb9e8bdd5a53203bb98eb77007e4876b53e Author: Atharva Tiwari iio/light: add new driver for macsmc This commit adds an IIO ambient light sensor driver for Apple SMC (macsmc-light) exposing left and right channels, and registers its MFD cell from macsmc-core when the ALV0 key is present. > diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig > index 462fff1ddef20..f84707edc6772 100644 > --- a/drivers/iio/light/Kconfig > +++ b/drivers/iio/light/Kconfig > @@ -457,6 +457,17 @@ config LV0104CS > To compile this driver as a module, choose M here: > the module will be called lv0104cs. > =20 > +config MACSMC_LIGHT > + tristate "Apple SMC Light Sensor" > + depends on MACSMC_ACPI > + help > + Say Y here if you have a Intel-based Mac. and you > + want support for light sensors. > + > + To compile this driver as a module, choose M here: > + the module will be called macsmc_light [Severity: Low] The Makefile builds macsmc-light.o, so the help text should say macsmc-light (with a hyphen and trailing period) rather than macsmc_light. Also, macsmc-light only uses architecture-independent interfaces from MFD_MACSMC_CORE. Should this depend on MFD_MACSMC_CORE (or MACSMC_ACPI || (MFD_MACSMC_CORE && COMPILE_TEST)) like the sibling macsmc drivers so it can be compile-tested on non-x86 builds? > diff --git a/drivers/iio/light/macsmc-light.c b/drivers/iio/light/macsmc-= light.c > new file mode 100644 > index 0000000000000..12d88035ad746 > --- /dev/null > +++ b/drivers/iio/light/macsmc-light.c [ ... ] > +static const struct iio_chan_spec macsmc_light_channels[] =3D { > + { > + .type =3D IIO_LIGHT, > + .channel =3D LEFT_LIGHT, > + .indexed =3D 1, > + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), > + .event_spec =3D macsmc_light_events, > + .num_event_specs =3D ARRAY_SIZE(macsmc_light_events), > + }, > + { > + .type =3D IIO_LIGHT, > + .channel =3D RIGHT_LIGHT, > + .indexed =3D 1, > + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), > + .event_spec =3D macsmc_light_events, > + .num_event_specs =3D ARRAY_SIZE(macsmc_light_events), > + }, > +}; [Severity: Medium] Should these channels use IIO_INTENSITY instead of IIO_LIGHT? Per Documentation/ABI/testing/sysfs-bus-iio, IIO_LIGHT (in_illuminanceY_raw) must report illuminance in lux after scale and offset. macsmc_light_read_raw() instead returns uncalibrated, unit-less raw SMC counts with no scale attribute. Exposing unit-less counts under in_illuminanceY_raw locks in wrong units for userspace. Without a lux conversion or scale factor, IIO_INTENSITY (in_intensityY_raw) is the documented type for unit-less light readings. [ ... ] > + ret =3D apple_smc_get_key_info(drv->smc, SMC_KEY(ALV0), &info); > + if (ret < 0) > + return -ENODEV; > + > + if (info.size < 3 || info.size > 10) > + return -ENODEV; > + > + drv->size =3D info.size; > + drv->single_sensor =3D info.size =3D=3D 10; [Severity: Medium] Does macsmc_light_probe() need to check ALV1 separately and register only one channel when a single sensor is present? On single-sensor Macs (10-byte ALV0), registering both channels exposes a nonexistent right channel that always returns 0 and never emits events. When ALV0 is 3 to 9 bytes on hardware without a matching-length ALV1, reading RIGHT_LIGHT with drv->size fails or reads past ALV1 while macsmc_light_event() still pushes RIGHT_LIGHT events. Querying ALV1 in probe and sizing indio_dev->num_channels accordingly would avoid both. > + drv->indio_dev =3D indio_dev; > + drv->nb.notifier_call =3D macsmc_light_event; > + ret =3D blocking_notifier_chain_register(drv->smc->event_handlers, &drv= ->nb); > + if (ret) > + return ret; > + > + ret =3D devm_add_action_or_reset(dev, macsmc_light_unregister_notifier,= drv); > + if (ret) > + return ret; > + > + indio_dev->name =3D "macsmc-light"; > + indio_dev->modes =3D INDIO_DIRECT_MODE; > + indio_dev->info =3D &macsmc_light_info; > + indio_dev->channels =3D macsmc_light_channels; > + indio_dev->num_channels =3D ARRAY_SIZE(macsmc_light_channels); > + > + return devm_iio_device_register(dev, indio_dev); [Severity: Medium] Can registering the SMC notifier before devm_iio_device_register() cause a use-after-free on probe failure and inverted teardown on unbind? apple_smc_acpi_probe() enables SMC interrupts before adding MFD children, so SMC_INT_ALS_CHANGE can invoke macsmc_light_event() while devm_iio_device_register() is still running or unwinding: CPU0 CPU1 macsmc_light_probe() blocking_notifier_chain_register() devm_iio_device_register() iio_device_register_eventset() event_interface =3D ev_int ... (cdev_device_add() fails) iio_device_unregister_eventset() apple_smc_acpi_notifier_work() macsmc_light_event() iio_push_event() ev_int =3D ...->event_interface kfree(ev_int) event_interface =3D NULL iio_event_enabled(ev_int) <-- use-after-free On normal unbind, devres LIFO order also runs iio_device_unregister() before macsmc_light_unregister_notifier(), leaving the notifier pushing events after the IIO device is torn down. Registering the notifier after devm_iio_device_register() succeeds fixes both. > diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c > index 1c14698285456..6014df4fe1c0a 100644 > --- a/drivers/mfd/macsmc-core.c > +++ b/drivers/mfd/macsmc-core.c [ ... ] > @@ -158,6 +162,13 @@ 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(ALV0))) { > + ret =3D devm_mfd_add_devices(dev, -1, apple_smc_acpi_light, > + ARRAY_SIZE(apple_smc_acpi_light), NULL, 0, NULL); > + if (ret < 0) > + return ret; > + } [Severity: Low] This isn't a bug, but devm_mfd_add_devices() here passes a literal -1 instead of PLATFORM_DEVID_AUTO (or PLATFORM_DEVID_NONE if a fixed single-instance name is required). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204131619.5059= -1-atharvatiwarilinuxdev@gmail.com?part=3D4