From patchwork Thu May 22 08:09:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 892115 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7348024EF90 for ; Thu, 22 May 2025 08:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747901418; cv=none; b=hJqiov7dtPkFePxqXzWbJv4RGNYpFoSEXwZ0PG8uCqFu6411AyXhL18+pA0AdF4N9I0P5SPXCSyKhnl5bun8OuJui9Tnn8ExIi7JkBzawbf50qZgGdQ9iD5ji8TuX/IfumyHhi7Si6uk4hYT/bePdl67TBHjgy+ZlcWM0EZwx0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747901418; c=relaxed/simple; bh=HFFAb0Lk0mw0G7zFblrqjg/2eT5TseIuXDJcPmd5Yyk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C3vDnYvyxMe/WxTtOxYHrfu97hAKj9juXOYSSVd692tJMoWCtmJ5Mat42SfK8sGxWCtKiELQrdgqukAzO20NqmDc6WMsOYU36oP13BU6kZRZkjKfKlphW8hO7Y74ZrXb+EA83LEkYdZPJ4oUNFGOhbSjYfGYM5umE7tc3S0k0G8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=CcpEC7Eh; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="CcpEC7Eh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=21pRsaR4ksDx6+MvixpJ8QaHqt3mZ65P1LMLxaR5cZM=; b=CcpEC7 EhXwTrq87jX0m1j13NSkvjU254GLnShsPP9pykN0ziQMd4DjBbjmuNL5lo30bEF5 o1wfh/Nh1BDx3BI+dd+MAsWC3uWqMdoS576sRQ/++rCKmYliV+K5ZN63ejVAOqO/ +4Mv404QSyS2OsMMzCf9+/JppGDa6YPj7cZE9P7RGMrBk497+X22OWeUGBrZMQEc yBMYdRqRcYClp7ISQtV+bt7DkR5PsssjDti72mL9jpWEKfa2mZfZY9h9iIFYEi9t wiVegzsJxnrpHBiMAw+eA2P6gfEsl9VuMzVDcuwiu4qCB0a5Y8qE1sJLTwTK+g13 /R5Yp10Lij/Cl56Q== Received: (qmail 3566362 invoked from network); 22 May 2025 10:10:13 +0200 Received: by mail.zeus03.de with UTF8SMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 22 May 2025 10:10:13 +0200 X-UD-Smtp-Session: l3s3148p1@v6PUArU1YrYgAwDPXwj7ADHm2wGe7qss From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: Alan Stern , Nikita Zhandarovich , Wolfram Sang , Hans Verkuil , Mauro Carvalho Chehab , linux-media@vger.kernel.org Subject: [PATCH v2 1/2] media: usb: hdpvr: disable zero-length read messages Date: Thu, 22 May 2025 10:09:54 +0200 Message-ID: <20250522080953.27323-5-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250522080953.27323-4-wsa+renesas@sang-engineering.com> References: <20250522080953.27323-4-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This driver passes the length of an i2c_msg directly to usb_control_msg(). If the message is now a read and of length 0, it violates the USB protocol and a warning will be printed. Enable the I2C_AQ_NO_ZERO_LEN_READ quirk for this adapter thus forbidding 0-length read messages altogether. Signed-off-by: Wolfram Sang --- drivers/media/usb/hdpvr/hdpvr-i2c.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/media/usb/hdpvr/hdpvr-i2c.c b/drivers/media/usb/hdpvr/hdpvr-i2c.c index 070559b01b01..54956a8ff15e 100644 --- a/drivers/media/usb/hdpvr/hdpvr-i2c.c +++ b/drivers/media/usb/hdpvr/hdpvr-i2c.c @@ -165,10 +165,16 @@ static const struct i2c_algorithm hdpvr_algo = { .functionality = hdpvr_functionality, }; +/* prevent invalid 0-length usb_control_msg */ +static const struct i2c_adapter_quirks hdpvr_quirks = { + .flags = I2C_AQ_NO_ZERO_LEN_READ, +}; + static const struct i2c_adapter hdpvr_i2c_adapter_template = { .name = "Hauppauge HD PVR I2C", .owner = THIS_MODULE, .algo = &hdpvr_algo, + .quirks = &hdpvr_quirks, }; static int hdpvr_activate_ir(struct hdpvr_device *dev) From patchwork Thu May 22 08:09:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 891801 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31A09261577 for ; Thu, 22 May 2025 08:10:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747901418; cv=none; b=UiTzPqp/2wDW3n+jVFXAf2sB/zD+koRaiWVh2X8Ps2l51zmvzTCaLhCpm8YNIujZFovFgCVpZ4cKtKha2Ue9KP3KHKsZY8cuoQt/MqbMWdsmusA9J5V5U/iQ1J4jXKUjziMfp00Kxlbo3tuTIPUYeOjsJ6XoyEoh2g/I2It6MJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747901418; c=relaxed/simple; bh=gZWzDNVHebgWuR8z8h4rKqz8GkgN8bzDRZ+jWx+po4w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dkAQ7D6Cjj0styWdS9PU/nmn7BnPI91KeJyMsYDafw/7mHQQfM24xap0mA8fvYYSBiWk2L9MivXkY0cS4fC2N18AzJeK6Bl+IjNpK2w2iyfcHaInpA3jDK6Jt/EWm5sJ6Z0hFsEfBmgpLAv2Wj2R3is1EeOO9hmr3OP2cH+lkIQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=dGPutsic; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="dGPutsic" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=B6MicjzLPnyPCnz7tSEQQ+cqSUWh42SmXecwz3n+3vE=; b=dGPuts icMerJ91wSZVAS0epL4OE2VdbWv6m3sk0b3Pw+Gmtb+TGDoY/gBkxv8p+znC5M5K qjj+yhNPWSEBfAEmreeLWUngl3ZoCtATUPRPdtxBJVjrw3JaVZPO1Wly01obFdIn CcoQcwjIPZrNXZwD0eCJb3w5OOaRk0kJwkTEH83qboPOT5V4K3cGOj9xI/F3QehT RcNmb6IDBVTzfYmasI8RcpxS0YvPXU1pIaSrQfaseSw7+fviyHSzQHjupSthK0Cn 5Ucn+83MCEGx/Jt06lSIghql96FRURiaDbzHcPSUYOVWAkS8+5S7RiWJa2cZsvWH lZ3wBthVVWKKUgag== Received: (qmail 3566416 invoked from network); 22 May 2025 10:10:14 +0200 Received: by mail.zeus03.de with UTF8SMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 22 May 2025 10:10:14 +0200 X-UD-Smtp-Session: l3s3148p1@YNHgArU1aLYgAwDPXwj7ADHm2wGe7qss From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: Alan Stern , Nikita Zhandarovich , Wolfram Sang , Hans Verkuil , Mauro Carvalho Chehab , linux-media@vger.kernel.org Subject: [PATCH v2 2/2] media: usb: hdpvr: use I2C core to handle only supported messages Date: Thu, 22 May 2025 10:09:55 +0200 Message-ID: <20250522080953.27323-6-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250522080953.27323-4-wsa+renesas@sang-engineering.com> References: <20250522080953.27323-4-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The HW can only do write-then-read transactions. This is a common limitation, so we can add an adapter quirk flag to let the I2C core enforce the checks instead of open coding them. Signed-off-by: Wolfram Sang --- drivers/media/usb/hdpvr/hdpvr-i2c.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/drivers/media/usb/hdpvr/hdpvr-i2c.c b/drivers/media/usb/hdpvr/hdpvr-i2c.c index 54956a8ff15e..9eacc85e3f11 100644 --- a/drivers/media/usb/hdpvr/hdpvr-i2c.c +++ b/drivers/media/usb/hdpvr/hdpvr-i2c.c @@ -124,32 +124,12 @@ static int hdpvr_transfer(struct i2c_adapter *i2c_adapter, struct i2c_msg *msgs, else retval = hdpvr_i2c_write(dev, 1, addr, msgs[0].buf, msgs[0].len); - } else if (num == 2) { - if (msgs[0].addr != msgs[1].addr) { - v4l2_warn(&dev->v4l2_dev, "refusing 2-phase i2c xfer with conflicting target addresses\n"); - retval = -EINVAL; - goto out; - } - - if ((msgs[0].flags & I2C_M_RD) || !(msgs[1].flags & I2C_M_RD)) { - v4l2_warn(&dev->v4l2_dev, "refusing complex xfer with r0=%d, r1=%d\n", - msgs[0].flags & I2C_M_RD, - msgs[1].flags & I2C_M_RD); - retval = -EINVAL; - goto out; - } - - /* - * Write followed by atomic read is the only complex xfer that - * we actually support here. - */ + } else { + /* do write-then-read */ retval = hdpvr_i2c_read(dev, 1, addr, msgs[0].buf, msgs[0].len, msgs[1].buf, msgs[1].len); - } else { - v4l2_warn(&dev->v4l2_dev, "refusing %d-phase i2c xfer\n", num); } -out: mutex_unlock(&dev->i2c_mutex); return retval ? retval : num; @@ -165,9 +145,9 @@ static const struct i2c_algorithm hdpvr_algo = { .functionality = hdpvr_functionality, }; -/* prevent invalid 0-length usb_control_msg */ +/* prevent invalid 0-length usb_control_msg and support only write-then-read */ static const struct i2c_adapter_quirks hdpvr_quirks = { - .flags = I2C_AQ_NO_ZERO_LEN_READ, + .flags = I2C_AQ_NO_ZERO_LEN_READ | I2C_AQ_COMB_WRITE_THEN_READ, }; static const struct i2c_adapter hdpvr_i2c_adapter_template = {