From patchwork Tue Jul 4 09:11:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 9824405 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C8EEB602F0 for ; Tue, 4 Jul 2017 09:11:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8F2827FB1 for ; Tue, 4 Jul 2017 09:11:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADA672844C; Tue, 4 Jul 2017 09:11:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61F5427FB1 for ; Tue, 4 Jul 2017 09:11:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752131AbdGDJLg (ORCPT ); Tue, 4 Jul 2017 05:11:36 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:39102 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751982AbdGDJLf (ORCPT ); Tue, 4 Jul 2017 05:11:35 -0400 X-IronPort-AV: E=Sophos;i="5.40,307,1496095200"; d="scan'208";a="281943394" Received: from vaio-julia.rsr.lip6.fr ([132.227.76.33]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jul 2017 11:11:22 +0200 Date: Tue, 4 Jul 2017 11:11:20 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Sebastian Reichel cc: Andy Shevchenko , Julia Lawall , kernel-janitors@vger.kernel.org, Gilles Muller , Nicolas Palix , Michal Marek , cocci@systeme.lip6.fr, "linux-kernel@vger.kernel.org" , Benjamin Tissoires , Bastien Nocera , Stephen Just , "Rafael J . Wysocki" , Len Brown , Robert Moore , Lv Zheng , Mika Westerberg , "linux-acpi@vger.kernel.org" , devel@acpica.org, "linux-pm@vger.kernel.org" Subject: Re: [PATCH] coccinelle: api: detect unnecessary le16_to_cpu In-Reply-To: <20170703182033.5stv5eq33et63coh@earth> Message-ID: References: <1498937290-12285-1-git-send-email-Julia.Lawall@lip6.fr> <20170703133602.ejcdu35ku3i63cj2@earth> <20170703171427.qtpodt7watymphac@earth> <20170703182033.5stv5eq33et63coh@earth> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Here is a revised version (not a patch because it doesn't support all of the various modes) and the results. It doesn't return anything beyond what was mentioned in previous mails. For the following code: ret = i2c_smbus_read_word_data(chip->client, reg << 1); val[0] = (u16)ret & 0xFF; val[1] = (u16)ret >> 8; do we want to see: put_unaligned(val,i2c_smbus_read_word_data(chip->client, reg << 1)); julia --- @@ expression e, x; @@ * x = i2c_smbus_read_word_data(...) ... when != x = e * le16_to_cpu(x) @@ expression e, e1, x, y; @@ * x = i2c_smbus_read_word_data(...) ... when != x = e * y = x; ... when != y = e1 * le16_to_cpu(y) @@ @@ * le16_to_cpu(i2c_smbus_read_word_data(...)) // ------------------------------------------------------------- @@ expression e, e1, e2, x; type T; @@ * x = cpu_to_le16(...) ... when != x = e * i2c_smbus_write_word_data(e1,e2,(T)x) @@ expression e, e1, e2, e3, x, y; type T; @@ * x = cpu_to_le16(...) ... when != x = e * y = x ... when != y = e3 * i2c_smbus_write_word_data(e1,e2,(T)y) @@ expression e1,e2; @@ * i2c_smbus_write_word_data(e1,e2,cpu_to_le16(...)) // ------------------------------------------------------------- @@ expression e1,e2; typedef u16; @@ * e1[0] = (u16)e2 & 0xFF; e1[1] = (u16)e2 >> 8; --- - means line of interest, not line to remove. diff -u -p a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -187,10 +187,7 @@ static int pca953x_write_regs_8(struct p static int pca953x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val) { - __le16 word = cpu_to_le16(get_unaligned((u16 *)val)); - return i2c_smbus_write_word_data(chip->client, - reg << 1, (__force u16)word); } static int pca957x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val) @@ -241,7 +238,6 @@ static int pca953x_read_regs_16(struct p int ret; ret = i2c_smbus_read_word_data(chip->client, reg << 1); - val[0] = (u16)ret & 0xFF; val[1] = (u16)ret >> 8; return ret; diff -u -p a/drivers/macintosh/windfarm_smu_sat.c b/drivers/macintosh/windfarm_smu_sat.c --- a/drivers/macintosh/windfarm_smu_sat.c +++ b/drivers/macintosh/windfarm_smu_sat.c @@ -77,18 +77,15 @@ struct smu_sdbp_header *smu_sat_get_sdb_ return NULL; } - err = i2c_smbus_read_word_data(sat->i2c, 9); if (err < 0) { printk(KERN_ERR "smu_sat_get_sdb_part rd len error\n"); return NULL; } - len = err; if (len == 0) { printk(KERN_ERR "smu_sat_get_sdb_part no partition %x\n", id); return NULL; } - len = le16_to_cpu(len); len = (len + 3) & ~3; buf = kmalloc(len, GFP_KERNEL); if (buf == NULL) diff -u -p a/drivers/macintosh/windfarm_lm75_sensor.c b/drivers/macintosh/windfarm_lm75_sensor.c --- a/drivers/macintosh/windfarm_lm75_sensor.c +++ b/drivers/macintosh/windfarm_lm75_sensor.c @@ -68,7 +68,6 @@ static int wf_lm75_get(struct wf_sensor } /* Read temperature register */ - data = (s32)le16_to_cpu(i2c_smbus_read_word_data(lm->i2c, 0)); data <<= 8; *value = data;