Nvidia driver/i2c-dev driver i2c failure

I’m hoping someone can enlighten me as to why there’s an if-test for symbol I2C_M_DMA_SAFE in function nv_i2c_algo_master_transfer() at approximately line 41 of file nv-i2c.c. Under what circumstances might it not exist in file linux/i2c.h?

In function i2cdev_ioctl_wdrw(), at approximately line 262 of i2c-dev driver file i2c-dev.c, this bit is set unconditionally, with the comment "memdup_user allocates with GFP_KERNEL, so DMA is ok ". This behavior is not the result of the userspace caller setting the flag, the driver sets it unconditionally. The result is that calls into i2c-dev using its ioctl() interface (as opposed to the read()/write() interface) always fail with error -EINVAL.

Ultimately, this mismatch should be addressed by the nvidia driver and/or i2c-dev. nv-i2c.c could be modified to always accept the flag, or driver i2c-dev could check for status code -EINVAL and retry without bit I2C_M_DMA_SAFE.

I am not aware of a i2c.h file in which I2C_M_DMA_SAFE is undefined, but apparently this is possible. When I build the nvidia module on my system, the bit is defined and the problem does not arise. However, as developer of ddcutil I receive bug reports from users whose version of the nvidia driver does not recognize the bit. I have not been able to discern a pattern.

As I said, ultimately this is a driver incompatibility problem, but driver fixes take a long time. In the short term, If I better understand the source of the problem I can code around it or provide instructions for my users as to how to work around it. Hence the original question.

And of course, this is a bug report.

Wolfram Sang, Linux I2C subsystem maintainer, responded as follows to my post on the linux-i2c mailing list:

I2C_M_DMA_SAFE is a hint for controller drivers that the buffer is DMA
capable. It is not something the controller driver needs to support
actively. Bailing out on this flag is wrong.