Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754885AbbGTOOn (ORCPT ); Mon, 20 Jul 2015 10:14:43 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:22586 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753824AbbGTOOl (ORCPT ); Mon, 20 Jul 2015 10:14:41 -0400 Date: Mon, 20 Jul 2015 17:14:24 +0300 From: Dan Carpenter To: Teodora Baluta Cc: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, daniel.baluta@intel.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] iio: magnetometer: add mmc34160 magnetometer driver Message-ID: <20150720141424.GJ5422@mwanda> References: <1437400350-25960-1-git-send-email-teodora.baluta@intel.com> <1437400350-25960-3-git-send-email-teodora.baluta@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1437400350-25960-3-git-send-email-teodora.baluta@intel.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1004 Lines: 38 On Mon, Jul 20, 2015 at 04:52:30PM +0300, Teodora Baluta wrote: > +static int mmc34160_raw_to_mgauss(int raw[3], int sens[3], int nfo, > + int index, int *val) > +{ > + switch (index) { > + case AXIS_X: > + *val = (raw[AXIS_X] - nfo) * 1000 / sens[AXIS_X]; > + break; > + case AXIS_Y: > + *val = (raw[AXIS_Y] - nfo) * 1000 / sens[AXIS_Y]; > + break; > + case AXIS_Z: > + *val = (raw[AXIS_Z] - nfo) * 1000 / sens[AXIS_Z]; > + break; > + default: > + return -EINVAL; > + } > + > + return 0; > +} We never pass invalid indexes here so this could be replaced with: static int mmc34160_raw_to_mgauss(int raw[3], int sens[3], int nfo, int index, int *val) { *val = (raw[index] - nfo) * 1000 / sens[index]; return 0; } regards, dan carpenter -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/