From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753155AbcAGME1 (ORCPT ); Thu, 7 Jan 2016 07:04:27 -0500 Received: from 8bytes.org ([81.169.241.247]:50441 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752887AbcAGMEY (ORCPT ); Thu, 7 Jan 2016 07:04:24 -0500 Date: Thu, 7 Jan 2016 13:04:22 +0100 From: Joerg Roedel To: Wan Zongshun Cc: iommu@lists.linux-foundation.org, Suravee Suthikulpanit , Borislav Petkov , Ray Huang , ken.xue@amd.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/6] iommu/amd: Add support for non-pci devices Message-ID: <20160107120422.GB19149@8bytes.org> References: <1451988444-4694-1-git-send-email-vincent.wan@amd.com> <1451988444-4694-6-git-send-email-vincent.wan@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1451988444-4694-6-git-send-email-vincent.wan@amd.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 05, 2016 at 05:07:23AM -0500, Wan Zongshun wrote: > -static inline u16 get_device_id(struct device *dev) > +static inline int match_hid_uid(struct device *dev, > + struct acpihid_map_entry *entry) > +{ > + const char *hid, *uid; > + > + hid = acpi_device_hid(ACPI_COMPANION(dev)); > + uid = acpi_device_uid(ACPI_COMPANION(dev)); > + > + if (!hid || !(*hid)) > + return -ENODEV; > + > + if (!uid || !(*uid)) > + return strcmp(hid, entry->hid); > + > + if (!(*entry->uid)) > + return strcmp(hid, entry->hid); > + > + return -ENODEV; > +} > + > +static inline u16 get_pci_device_id(struct device *dev) > { > struct pci_dev *pdev = to_pci_dev(dev); > > return PCI_DEVID(pdev->bus->number, pdev->devfn); > } > > +static inline int get_acpihid_device_id(struct device *dev, > + struct acpihid_map_entry **entry) > +{ > + struct acpihid_map_entry *p; > + > + list_for_each_entry(p, &acpihid_map, list) { > + if (!match_hid_uid(dev, p)) { > + if (entry) > + *entry = p; > + return p->devid; > + } > + } > + return -EINVAL; > +} > + > +static inline u16 get_device_id(struct device *dev) > +{ > + if (dev_is_pci(dev)) > + return get_pci_device_id(dev); > + else > + return get_acpihid_device_id(dev, NULL); > +} This is not robust, get_acpihid_device_id() returns int and can return a negative value. This gets lost when converting it to u16 here. So either you add error handling for get_acpihid_device_id() in get_device_id() or you change get_device_id() to return int too and handle the error at the callers of get_device_id(). Joerg