From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.auroraos.dev (unknown [95.181.193.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14FE01DDC1B; Sun, 23 Aug 2026 07:52:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.181.193.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787471542; cv=none; b=nai5g/26BWkcg4KftCad5JYq5lr+ooypsuyvmS5TNkIFOOQsLfe+wUH/jXXHBD85VTGmgvv2K6hX3ahjhxVCCmELgVRvwEEF7Q5lO1vc3zdkPrFQZ6cc8yXgDPoAd5xyaVg4tg/TCGiWCV6TNuYMQBgLa9pBPwAtcO2dBckFJCY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787471542; c=relaxed/simple; bh=NIvaPpYg5CNn9ZbZfozbb0b3bh4XfwFj+3DdupWVob4=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=jUMQQgTvKPViDPWez9W2vEbETaO95AzrwP/snKqItOgm39gfK2cbHMErRa77gQMUGNoyYA75GqZiG1Pdk5Q33S3X+zMpq1F2/Ekj2rjX8j4jGbBQOt5PnFlAyvhG+YcC4L93P6vVWw6H+Vi8QvkNpZvhAJln/jrV4FFe5e8+6No= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=auroraos.dev; spf=pass smtp.mailfrom=auroraos.dev; arc=none smtp.client-ip=95.181.193.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=auroraos.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=auroraos.dev Received: from [192.168.2.104] (91.79.20.171) by exch16.corp.auroraos.dev (10.189.209.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1847.3; Sun, 23 Aug 2026 10:52:13 +0300 Message-ID: Date: Sun, 23 Aug 2026 10:52:12 +0300 Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] r8152: simplify loops in generic_ocp_{read,write}() To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , , References: <20260822202155.18632-1-s.shtylyov@auroraos.dev> Content-Language: en-US From: Sergey Shtylyov In-Reply-To: <20260822202155.18632-1-s.shtylyov@auroraos.dev> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: exch16.corp.auroraos.dev (10.189.209.38) To exch16.corp.auroraos.dev (10.189.209.38) On 8/22/26 11:21 PM, Sergey Shtylyov wrote: > In generic_ocp_{read,write}(), the *while* loops look very strange: > the last iteration is executed differently to the prior ones, doing > some useless assignments before *break*. Move the code for the last > iteration out of the loop bodies, dropping the pointless statements > as well... > > Found by Linux Verification Center (linuxtesting.org) with the Svace > static analysis tool. > > Signed-off-by: Sergey Shtylyov Actually, scratch this patch -- it's not entirely correct... :-/ [...]> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c > index f61686433031..de9738bdce85 100644 > --- a/drivers/net/usb/r8152.c > +++ b/drivers/net/usb/r8152.c > @@ -1431,27 +1431,19 @@ static int generic_ocp_read(struct r8152 *tp, u16 index, u16 size, > if ((u32)index + (u32)size > 0xffff) > return -EPERM; > > - while (size) { > - if (size > limit) { > - ret = get_registers(tp, index, type, limit, data); > - if (ret < 0) > - break; > - > - index += limit; > - data += limit; > - size -= limit; > - } else { > - ret = get_registers(tp, index, type, size, data); > - if (ret < 0) > - break; > + while (size > limit) { > + ret = get_registers(tp, index, type, limit, data); > + if (ret < 0) > + goto error1; > > - index += size; > - data += size; > - size = 0; > - break; > - } > + index += limit; > + data += limit; > + size -= limit; > } > I forgot to check size for 0 here... > + ret = get_registers(tp, index, type, size, data); > + > +error1: > if (ret == -ENODEV) > rtl_set_unplug(tp); > > @@ -1498,31 +1490,24 @@ static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen, > if (byen != BYTE_EN_DWORD) > size -= 4; > > - while (size) { > - if (size > limit) { > - ret = set_registers(tp, index, > - type | BYTE_EN_DWORD, > - limit, data); > - if (ret < 0) > - goto error1; > - > - index += limit; > - data += limit; > - size -= limit; > - } else { > - ret = set_registers(tp, index, > - type | BYTE_EN_DWORD, > - size, data); > - if (ret < 0) > - goto error1; > - > - index += size; > - data += size; > - size = 0; > - break; > - } > + while (size > limit) { > + ret = set_registers(tp, index, type | BYTE_EN_DWORD, > + limit, data); > + if (ret < 0) > + goto error1; > + > + index += limit; > + data += limit; > + size -= limit; > } > And here... > + ret = set_registers(tp, index, type | BYTE_EN_DWORD, size, data); > + if (ret < 0) > + goto error1; > + > + index += size; > + data += size; > + > /* Set the last DWORD */ > if (byen != BYTE_EN_DWORD) > ret = set_registers(tp, index, type | byen, 4, data); MBR, Sergey