Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp898289pxk; Thu, 10 Sep 2020 01:14:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzaLreQPF+xj9nNgF+pKG+vkFpPLrGLef8+gg7ngk3T3fAE9NzJQZSRM8qjCtuEkoUJTZvN X-Received: by 2002:a17:906:69d5:: with SMTP id g21mr7184408ejs.461.1599725698772; Thu, 10 Sep 2020 01:14:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599725698; cv=none; d=google.com; s=arc-20160816; b=GAZtXMjRnTY9nKl2auEeueGO3y8HYE1MTChXk+QIt/ieweuKe+mL7i2Pc7+gP5BK4m Ix7qLQzhX6FTStMxcGSp1devLzK/lkI8z/kB4F+9liGXyDf67SDwBl47VYAjp2X2H79e 7fDVaL41oT0hvA9tamV0yGbWxJ/fxQwWHDVLvolWeJo1+lr7K4w/V/Am7fBvKXXMd7gu +mprpLUwASAVYz++IsbwaHiBnKOc6yLHP8vTSSJDlRo5lsEtmorIw+K9vJi3ylD6oUg4 nF6fqcLGo1TdhrFs2SiPHaIkOnDL6udDaV/ZDsdWDvC7GBdOXkXp4HU2BKNc+QPtUBIs fN9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=54uBTtnKpSpkFGPs3XgpzGvJS3KRt5jBRnPrl+FwSoU=; b=hr0KZAf1Qqsp7YApca+uNF5XJZt2lwxmA+9PhuDBopGUcunAa966I9Xyf30U0++Vwg NU6tLVl8ZZ0KSnK/qXXJ4UUuSnHUBzoIDDO37nFqtJy7BZpO9DaA82uJk1MKB9OIRz7E JrFXvtmoaMb1qt5U5243iMxi9x3TkUWIMJHAF5Jr9vS3/gibvT+81Y/QMKveEAIFne6A LmIcZZl1dzg04uVFE6MxRiQwFM6nY/CDN7WbD+rzkZXuoegrwxhO1aqjwDRfuAv6R1JX Q8qSJtrd7gk7aERkWnQnMC8La1XkKL2dHn8mbHoUlCW6+SnXvhOv/ddbnc5LoZcIOsNL XEdw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t23si3005161ejs.552.2020.09.10.01.14.36; Thu, 10 Sep 2020 01:14:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729525AbgIJIKd (ORCPT + 99 others); Thu, 10 Sep 2020 04:10:33 -0400 Received: from marcansoft.com ([212.63.210.85]:49254 "EHLO mail.marcansoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726381AbgIJIKa (ORCPT ); Thu, 10 Sep 2020 04:10:30 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: marcan@marcan.st) by mail.marcansoft.com (Postfix) with ESMTPSA id A246B3FA50; Thu, 10 Sep 2020 08:10:24 +0000 (UTC) Subject: Re: [PATCH v2] usb: serial: Repair FTDI FT232R bricked eeprom To: James Hilliard , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Johan Hovold , Linux Kernel Mailing List , Russ Dill References: <20200909193419.2006744-1-james.hilliard1@gmail.com> <20200910054933.GA525707@kroah.com> From: Hector Martin Message-ID: Date: Thu, 10 Sep 2020 17:10:20 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: es-ES Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/09/2020 15.45, James Hilliard wrote: >>> +static int ftdi_write_eeprom(struct usb_serial_port *port, u8 addr, u16 data) >>> +{ >>> + struct usb_device *udev = port->serial->dev; >>> + int rv; >>> + >>> + rv = usb_control_msg(udev, >>> + usb_sndctrlpipe(udev, 0), >>> + FTDI_SIO_WRITE_EEPROM_REQUEST, >>> + FTDI_SIO_WRITE_EEPROM_REQUEST_TYPE, >>> + data, addr, >>> + NULL, 0, WDR_TIMEOUT); >>> + if (rv < 0) >>> + dev_err(&port->dev, "Unable to write EEPROM: %i\n", rv); >> >> You don't check for a "short write"? > From my understanding the hardware only accepts 2 byte writes, and > the non-counterfeits actually only commit writes on odd addresses > while they buffer writes on even(this difference is what FTDI's windows > driver exploits). So I guess this should be "if (rv < 2)"? It's not "data" anyway, the data word gets sent in control message headers. Unless I'm mistaken rv == 0 on success, so the code should be correct as-is. >> >>> + return rv; >>> +} >>> + >>> +static u16 ftdi_checksum(u16 *data, int n) >>> +{ >>> + u16 checksum; >>> + int i; >>> + >>> + checksum = 0xaaaa; >>> + for (i = 0; i < n - 1; i++) { >>> + checksum ^= be16_to_cpu(data[i]); >>> + checksum = (checksum << 1) | (checksum >> 15); >>> + } >> >> What type of function is this, don't we have all of the needed checksum >> functions in the kernel already? > Some custom crc16 style checksum I guess, I'm not seeing anything > in the kernel that's the same, although I might not be looking in the > right places. This isn't a CRC, it's some random xor all the words thing with a somewhat pointless rotation in the way. I'd be surprised if anything elses uses this particular function. Pretty sure other drivers are littered with stuff like this too, hardware manufacturers love to reinvent checksums. -- Hector Martin (hector@marcansoft.com) Public Key: https://mrcn.st/pub