lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240828160511.307768-1-apokusinski01@gmail.com>
Date: Wed, 28 Aug 2024 18:05:11 +0200
From: Antoni Pokusinski <apokusinski01@...il.com>
To: linux@...ck-us.net
Cc: apokusinski01@...il.com,
	jdelvare@...e.com,
	linux-hwmon@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: Re: [PATCH v3] hwmon: (sht4x): add heater support

Hello,

I've been thinking on how to approach the problem of NACKs received
from the sensor while the heater is on but I haven't found
a perfectly satisfying solution either. This is due to the fact that
the device does not provide any way to check if the heater is on/off.

1. I guess that the simplest possible approach would involve sleeping
in `heater_enable_store()`:
  
  ssize_t heater_enable_store() {
    ...
    mutex_lock(data->lock);
    ret = i2c_master_send(data->client, &cmd, SHT4X_CMD_LEN);
    msleep(...) /* for >100 or >1000 ms */
    mutex_unlock(data->lock);
    ...
  }

This way, the user would have to wait for the heating to complete in
order to read RH or temperature measurement. However, I find this
solution unacceptable since it's completely unnecessary for the user
to wait for the heating to complete.

2. A better solution could be possibly to use a wait queue in order
to defer the job of enabling the heater:

  struct sht4x_data {
    ...
    struct work_struct* heater_work; /* This would be initialized
                                        with the handler described
                                        below */
  }

The task of sending the "heater_enable" command and sleeping would be
performed by the worker function:

  static void heater_enable_handler(struct work_struct *work) {
    ...
    mutex_lock(data->lock);
    ret = i2c_master_send(data->client, &cmd, SHT4X_CMD_LEN);
    msleep(...) /* for >100 or >1000 ms */
    mutex_unlock(data->lock);
    ...
  }

And that above mentioned work would be scheduled
in `heater_enable_store()`:

  ssize_t heater_enable_store() {
    ...
    schedule_work(data->heater_work);
    ...
  }

I think that this approach with work queue is better since the user
doesn't have to wait for the heating to complete and the RH or
temperature measurements can also be retrieved without the NACK error
(even though the user still may have to wait for the heater to be
off), since the `data->lock` mutex is used to guard both measurement
reads from the sensor and the heating in `heater_enable_handler`.

I'm worried though about the situation where the user writes 1 to
"heater_enable" while it's already enabled. Since the `work_struct`
is already on the queue, the `heater_enable_store` would return an
error and I see no easy solution to this for now.

Regards,
Antoni Pokusinski

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ